Difference between revisions of "Category:LSL String"

From Second Life Wiki
Jump to navigation Jump to search
Line 70: Line 70:
do;while(i && ~llSubStringIndex(chrs, llGetSubString(src, (i = -~i), i)));
do;while(i && ~llSubStringIndex(chrs, llGetSubString(src, (i = -~i), i)));
return llDeleteSubString(src, 0xFFFF0000, ~-i);
return llDeleteSubString(src, 0xFFFF0000, ~-i);
}
string TrimBoth(string src, string chrs)
{
    integer i = ~llStringLength(src);
    do;while(i && ~llSubStringIndex(chrs, llGetSubString(src, (i = -~i), i)));
    i = llStringLength(src = llDeleteSubString(src, 0xFFFF0000, (~-(i))));
    do;while(~llSubStringIndex(chrs, llGetSubString(src, (i = ~-i), i)) && i);
    return llDeleteSubString(src, (-~(i)), 0xFFFF);
}
}
</pre>
</pre>
</div></div>
</div></div>

Revision as of 02:04, 17 March 2007

A string is a text data. String values are enclosed in quotes when you define them. You can use every letter or number in a string!


String examples:

"Hello Avatar!"
"Yes"
"No"
"It's 10 o'clock."
"I am 21 years old!"
EOF


Variable: string name;

string name;

Declares a variable of type string named name, with the value ""

• variable name variable name

Variable: string name = value;

string name = value;

Declares a variable of type string named name, with the value value.

• variable name variable name
• expression value string expression or constant

Typecast: (string)value

string name;

Converts value to a value of type string.

• expression value variable name

Examples

integer int = 48934;
string str = (string)int;
string str_2;
str_2 = str;

Useful Functions

string TrimRight(string src, string chrs)
{
	integer i = llStringLength(src);
	do;while(~llSubStringIndex(chrs, llGetSubString(src, i = ~ -i, i)) && i);
	return llDeleteSubString(src, -~i, 0xFFFF);
}

string TrimLeft(string src, string chrs)
{
	integer i = ~llStringLength(src);
	do;while(i && ~llSubStringIndex(chrs, llGetSubString(src, (i = -~i), i)));
	return llDeleteSubString(src, 0xFFFF0000, ~-i);
}
string TrimBoth(string src, string chrs)
{
    integer i = ~llStringLength(src);
    do;while(i && ~llSubStringIndex(chrs, llGetSubString(src, (i = -~i), i)));
    i = llStringLength(src = llDeleteSubString(src, 0xFFFF0000, (~-(i))));
    do;while(~llSubStringIndex(chrs, llGetSubString(src, (i = ~-i), i)) && i);
    return llDeleteSubString(src, (-~(i)), 0xFFFF);
}