Posted By: tolu619
How to extract number from a string? - 11/17/14 16:46
I'm trying to check if the player is in any region and if so, check if the region name starts with the word "abyss". If it does, it would be "abyss1", "abyss2", "abyss3", etc. So I want to extract the number at the end of the string and convert it to an integer. I've played around with most of the string manipulation functions defined in strio.c but somehow, I keep getting empty pointer exceptions.
And I tried many other similar permutations
Code:
//GLOBAL VARAIBLES STRING* AbyssNameString = str_create(""); STRING* AbyssNumberString = str_create(""); STRING* TempString = str_create(""); STRING* ComparisonString = str_create("Abyss"); //THESE LINES ARE INSIDE PLAYER'S WHILE(1) LOOP if(region_find(AbyssNameString, my.x))//check if ent is in region & store name of region { if(str_cmpni(AbyssNameString, "Abyss")) //if the region is an abyss { str_parse_head(AbyssNumberString, AbyssNameString, "Abyss"); //store number that comes after 'abyss' if(region_check(AbyssNameString,vMin,vMax)) { vec_set(my.x, Player1RespawnPosition[str_to_num(AbyssNumberString)]); } } } //THIS DOESN'T WORK
Code:
if(region_find(AbyssNameString, my.x))//check if ent is in region & store name of region { TempString = str_cut(NULL, AbyssNameString, 1, 5); //store first 5 letters in TempString if(str_cmpi(TempString, "Abyss")) //if the region is an abyss { str_parse_head(AbyssNumberString, AbyssNameString, "Abyss"); //store number that comes after 'abyss' if(region_check(AbyssNameString,vMin,vMax)) { vec_set(my.x, Player1RespawnPosition[str_to_num(AbyssNumberString)]); } } } //THIS DOESN'T WORK
Code:
if(region_find(AbyssNameString, my.x))//check if ent is in region & store name of region { TempString = str_cut(NULL, AbyssNameString, 1, 5); //store first 5 letters in TempString if(str_cmpi(TempString, ComparisonString)) //if the region is an abyss { str_parse_head(AbyssNumberString, AbyssNameString, "Abyss"); //store number that comes after 'abyss' if(region_check(AbyssNameString,vMin,vMax)) { vec_set(my.x, Player1RespawnPosition[str_to_num(AbyssNumberString)]); } } } //THIS DOESN'T WORK
And I tried many other similar permutations