SA-MP Forums Archive
Split a string - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Split a string (/showthread.php?tid=208509)



Split a string - GiS - 08.01.2011

Hey, I got 3 numbers which a person gave me via a dialog. So it's saved in inputtext. These 3 numbers are already split with a ":". For example: 1:324:26126

Now I want to have each part in a extra string without the ":". For example: string1: 1, string2: 324, string3: 26126

How to do that?


Re: Split a string - Retardedwolf - 08.01.2011

sscanf2/unformat


Re: Split a string - armyoftwo - 08.01.2011

pawn Код:
new number1;
new number2;
new number3;
sscanf(inputtext, "p<:>iii", number1, number2, number3);
Hope it works


Re: Split a string - GiS - 08.01.2011

How can I remove the ":" with sscanf?


Re: Split a string - armyoftwo - 08.01.2011

It will remove it automatically


Re: Split a string - GiS - 08.01.2011

pawn Код:
new number1, number2, number3, str[256];
sscanf(inputtext, "p<:>iii", number1, number2, number3);
format(str, sizeof(str), "1. %i 2. %i 3. %i", number1, number2, number3);
SendClientMessage(playerid, COLOR_RED, str);
This is now showing the results. Well, when I insert 01:02:03 it says: number1 = 1 number2 = 2 number3 = 3 (1. 1 2. 2 3. 3)


Re: Split a string - armyoftwo - 08.01.2011

pawn Код:
new number1, number2, number3, str[256];
sscanf(inputtext, "p<:>iii", number1, number2, number3);
format(str, sizeof(str), "1. 0%i 2. 0%i 3. 0%i", number1, number2, number3);
SendClientMessage(playerid, COLOR_RED, str);
I can't think of any other way atm


Re: Split a string - GiS - 08.01.2011

That's not good because I really need it. Anyone got an idea?

EDIT: And how can I check if there are 3 ":" in the string?


Re: Split a string - Krx17 - 08.01.2011

Quote:
Originally Posted by GiS
Посмотреть сообщение
That's not good because I really need it. Anyone got an idea?

EDIT: And how can I check if there are 3 ":" in the string?
Loop.

Use it as so: stringCount("1:2:3", ":", 5);
pawn Код:
stock stringCount(string[], token, length)
{
    new count;
    for(new i = 0; i < length; i++)
    {
        if(string[i] == token)
            count++;
    }
    return count;
}



Re: Split a string - Mаkaveli - 08.01.2011

Quote:
Originally Posted by GiS
Посмотреть сообщение
That's not good because I really need it. Anyone got an idea?

EDIT: And how can I check if there are 3 ":" in the string?
https://sampwiki.blast.hk/wiki/Strfind as i know