Cicode Programming Reference > Converting and Formatting Cicode Variables > Formatting Text Strings

Formatting Text Strings

A string in Cicode is represented as text positioned between double quote ( " ) delimiters. For example:

"This is my text string."

A string value can be assigned to a string variable. For example:

STRING sMyStringVariable;
sMyStringVariable = "This is my text string.";

More than one string can be joined together (concatenated) using the Cicode 'plus' mathematical operator ( + ). For example:

STRING sMyStringVariable;
sMyStringVariable = "This is my text string." + "This is my second text string.";

The two strings would be joined together and assigned to the string variable sMyStringVariable. However, if subsequently displayed somehow, like in the following MESSAGE example, the concatenated string would look wrong because there is no space character positioned between the string sentences.

STRING sMyStringVariable;
sMyStringVariable = "This is my text string." + "This is my second text string.";
MESSAGE("String Concatenation Example",sMyStringVariable,32);

To overcome this potential formatting problem, you could include an extra space as the last character in the strings, or include the space as a third string in the concatenation. For example:

sMyStringVariable = "This is my text string. " + "This is my
second text string. ";

or

sMyStringVariable = "This is my text string." + " " + "This is my
second text string. ";

However, these are considered poor programming practices and not recommended. Instead, you can use special string formatting commands known as escape sequences.

If the two strings (as used in the previous example), were formatted using appropriate escape sequences positioned within the strings, and subsequently displayed somehow, like in the following MESSAGE example, the concatenated string would look different, For example:

STRING sMyStringVariable;
STRING sNewLine = "^n";
sMyStringVariable = "This is my text string." + sNewLine + "This is my second text string.";
MESSAGE("String Concatenation Example",sMyStringVariable,32);

Strings and string variables can also be concatenated as in the previous example. Be aware of how the newline escape sequence ( ^n ) was assigned to the string variable sNewLine, and how this value was concatenated between the other strings and assigned to the string variable sMyStringVariable for display in the MESSAGE function.

See Also

Converting and Formatting Cicode Variables

Using Cicode Files