Exploding 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)
+--- Thread: Exploding string (
/showthread.php?tid=590688)
Exploding string -
Chriham3 - 02.10.2015
Hello, I have a string like
"Hello||Sup||Nothing, wbu?||Just chilling", and I want to use the || as a delimiter, and loop through each to
Код:
SendClientMessageToAll(-1, "Hello");
SendClientMessageToAll(-1, "Sup");
SendClientMessageToAll(-1, "Nothing, wbu?");
etc..
The amount of messages is fluctuating. I haven't scripted on SA-MP for several years, so I am extremely rusty. Something like PHP's explode function.
In PHP, it's
Код:
<?php
$string = "Hello||Sup||Nothing, wbu?||Just chilling";
$messages = explode("||", $string);
foreach($messages as $message)
{
echo $message . "<br>";
}
?>
which outputs
Код:
Hello
Sup
Nothing, wbu?
Just chilling
Any help would be appreciated, thanks.
AW: Exploding string -
Kaliber - 02.10.2015
I dont't know exactly what u want, but do it like this:
PHP код:
SendExplodedMessage(playerid,-1,"Hi|This|is|a|Test");
/*
Send the player:
Hi
This
is
a
Test
*/
stock SendExplodedMessage(playerid,color,const string[])
{
new tmp[128],p=strfind(string,"|"),old=-1;
if(p==-1) return SendClientMessage(playerid,color,string);
for(new i=p; ; i=strfind(string,"|",false,i+1)) {
strmid(tmp,string,old+1,(i==-1)?strlen(string):i,sizeof(tmp)),old=i;
SendClientMessage(playerid,color,tmp);
switch(i) {
case -1: break;
}
}
return 1;
}
Re: Exploding string -
Lordzy - 02.10.2015
https://sampforum.blast.hk/showthread.php?tid=85697
Re: Exploding string -
Vince - 02.10.2015
I would rather look at the problem in the underlying system. I don't know the specifics of your system, but delimited strings are nearly always a bad way to transmit or store multiple pieces of data.