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


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
StringSub failing in the background?
Apjjm Offline
Is easy to say

Posts: 496
Threads: 18
Joined: Apr 2011
Reputation: 52
#2
RE: StringSub failing in the background?

Your array "ret" is empty from my quick glance, and you are also seem to be acessing the n+1th element of the array. I changed it's definition to:

string[] ret = {""};
and the problem line to
ret[ret.length() - 1] = StringSub(str, start, i); // Seems to be haulting
and it worked. After this, since i am assuming you want to split the string based on the delimiter into elements of the array, an:
ret.resize(ret.length() + 1);
Would help out with that.

Hope that helps Wink. I've also built a string splitting system based on 1 char delimiters - it's in the "string list" stuff in the wiki thread if you want to take a gander - though I doubt you'd have much to gain from it as your approach would support delims of an arbitrary length.

Edit:
Also, your int parsing function will crash the game if the assumed invariant is broken and a negative number or non-int is passed in. I think parsing character-by-character is probably going to be a better approach here than looping up to the number (it will certainly be more efficient as number size grows). I've been using this parse I wrote for a while now (refining it quite a bit since it's first appearance on the forums) - it may help you out a little.
//Helper function: Used to determine if the char "digit" represents a number
//Returns: (-1) if not a number. Else returns the digit (0-9).
int  _ParseDigit(uint8 digit) {
    int d = digit-48; //48 is ASCII code for 0
    return ((d >= 0)&&(d<=9)) ? d : -1; }

//Parses ALL the numbers from a string on a by-char basis.
//Sign ignored. No numbers returns 0.
uint parseStringUInt(string &in asString) {
    uint output = 0;
    for(uint i=0; i<asString.length(); i++)
     {
       int digit = _ParseDigit(asString[i]); //Get the digit represented by char at i (-1 if not digit)
       output = (digit > -1)?(10*output+digit):(output); //Append digit to end of output num if char is a digit.
     }
    return output;
}
(This post was last modified: 09-27-2011, 12:31 AM by Apjjm.)
09-27-2011, 12:14 AM
Find


Messages In This Thread
RE: StringSub failing in the background? - by Apjjm - 09-27-2011, 12:14 AM



Users browsing this thread: 1 Guest(s)