Facebook Twitter YouTube Frictional Games | Forum | Newsletter | Dev Blog | Dev Wiki | Support | Gametee

Post Reply 
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help understanding this
Author Message
Your Computer Offline

Posts: 3,456
Joined: Jul 2011
Reputation: 235
Post: #2
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.

Tutorials: From Noob to Pro
01-20-2012 11:28 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply 

Messages In This Thread
Need help understanding this - Shadowfied - 01-20-2012, 10:06 AM
RE: Need help understanding this - Your Computer - 01-20-2012 11:28 AM

User(s) browsing this thread: 1 Guest(s)