I have a string variable in a graph. I need to manage this as an array of bytes. I tried the following:
string graphvariable;
byte arrayvariable;
arrayvariable = graphvariable;
I also tried it as an array on the string side, like one would of a string in C:
for (a = 0; a < max; a++)
arrayvariable[a] = graphvariable[a];
Neither is clean. How can I manage this?
I need to manage the string at an array of bytes to manipulate the way required (and put it back into a string).
Thanks!
String can not be directly converted to bytes (array of bytes). One of the reasons is that string consists of chars, which are 16bit (unicode).
You may access any character of string using charAt() function. You can also construct an array of strings (even one character strings) and then
work with individual chars.
string graphvariable;
string[] arrayvariable;
int a;
//copy graphvariable to arrayvariable char by char
for (a = 0; a < length(graphvariable); a++){
append(arrayvariable, charAt(graphvariable,a);
}
//also following works
arrayvariable[5]="X";
See Container library for more details about arrays/lists in CTL.
Hi dmatusow,
There are functions byte2str and str2byte, but those uses encoding as parameter so they may perform conversion.
See http://doc.cloveretl.com/documentation/ … -ctl2.html for details.