String Manipulation

RobotC provide native support for string variables. This is an extension beyond the normal capabilities found in the ‘C’ language; in standard ‘C’ strings are manipulated with arrays of ‘;char’.

String variables can contain up to 20 characters;  20 characters was chosen because it is more characters than will fit on one line of the NXT display.

Native support means that normal “opcodes” apply to strings. In particular, you can:

string stringA;                 // Define a string variable

string stringB = “Hello World;  // Define a string variable with an initial value

string stringD[10];             // Define a string array of 10 elements.

stringA = stringB;

stringA = “Hello World”;

stringA  = stringB + stringC;  // stringA           is the concatenated result of ‘stringb’ with ‘stringB’

stringA += stringB;            // stringA           is added to the end of stringA

stringA += “More Characters”;  // “More Characters” is added to the end of stringA

if (stringA == stringB) . . .

if (stringA >= stringB) . . .

if (stringA <  stringB) . . .

etc

The following functions also apply to string variables.

 

StringDelete(sDest, nIndex, nSize);

Deletes a substring from a string

 

StringFind(sDest, nIndex, sSearch);

Finds the position in a string of the selected substring

 

StringFormat(sDest, sFmtSpec, nParm1, nParm2);

Formats a string using the specified format string and up to two parameters for formating

 

strLen(sString)

Functions returns the size of a string