Your Computer
SCAN ME!
Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation:
235
|
RE: Need help understanding this
Technically, a string is generally a char array. In other words, "some text" is the same as {'s', 'o', 'm', 'e', ' ', 't', 'e', 'x', 't'}. Therefore a character in a string can be accessed by its index; starting from 0 if read from left to right, starting from -1 if read from right to left. The numbers you're providing in StringSub() is the starting index and the number of characters you want to include from that index. So, StringSub("some text", 4, 2) will return " t".
You do not want to go passed the size of the string itself, as this may crash the game. So try to avoid using string.length() for the third parameter. Also, do note that providing -1 for the third parameter will tell the function to stop at the end of the string. So, StringSub("some text", 4, -1) will return " text"; StringSub("some text", 4, -2) will return " tex"; and so on.
|
|
01-20-2012, 11:28 AM |
|