Scripting - String Manipulation

This forum contains common answers to questions and tutorials produced for the community.
pbj
Posts: 10
Joined: Mon Oct 11, 2010 3:02 pm

Scripting - String Manipulation

Post by pbj » Fri Mar 18, 2011 2:28 pm

I'm having difficulty manipulating strings in my scripts. Specifically, I need to use a substring function and a split (tokenizer) function. I'm able to read a file from memory line-by-line, but I get the non-printable line terminators (CR/LF) at the end of my strings, and I need to cut these off. I also need to split a string on a delimiter. I've found the following page on the AngelScript site:

http://www.angelcode.com/angelscript/sd ... tring.html

which has the two functions I need, but the compiler does not seem to like these. Could you please tell me if these are compatible with PowerVision scripting and if so explain how to use them? Any help would be much appreciated.
jtilley
Enovation Controls Development
Enovation Controls Development
Posts: 31
Joined: Wed Sep 08, 2010 10:02 am

Re: Scripting - String Manipulation

Post by jtilley » Tue Mar 22, 2011 12:43 pm

The substring and split string functions are not available in the PowerVision AngelScript implementation. The string available in scripting is the AngelScript string (STL) object.

Unfortunately, this means that you'll have to create any string handling utilities you need manually. However, AngelScript does allow a string to be treated like a character array, so you can use that to iterate through the string and parse it. I've attached a file containing a few string utilities that were written in AngelScript for a PowerVision configuration. You should be able to use the getCsvFields function as an example of how to split a string on a delimiter.

As far as removing the line terminators, the string.resize(int length) function should work for that. For instance

Code: Select all

str.resize(str.length() - 2)
would remove the last two characters off a string.

Let me know if you have any questions.
Attachments
stringUtils.cpp
AngelScript string utilities
(3.62 KiB) Downloaded 83 times
Joe Tilley
Software Engineer
FW Murphy