Inserting a character into 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: Inserting a character into a string. (
/showthread.php?tid=278882)
Inserting a character into a string. -
iPLEOMAX - 24.08.2011
I've been trying a lot of methods and some fail and some work a little.. Hmm..
Suppose I have a string "trololo1o1o1olo1"
Now How can I replace all the "1"s here with "_1" so it looks like: "trololo_1o_1o_1olo_1"?
I used loops,strfind,strins.. they all failed cuz I'm messing up somewhere..
Any Help Please
![Cheesy](images/smilies/biggrin.png)
?
Re: Inserting a character into a string. -
Wesley221 - 24.08.2011
Use str_replace.
pawn Code:
str_replace("1 /*the character you want to replace*/ ", "_1 /* what will replace the character */ ", "trololo1o1o1olo1 /* in which string do you want this to happen*/ ");
If you will do this in a printf line, this will output the "trololo_1o_1o_1olo_1" like you said
Re: Inserting a character into a string. -
=WoR=Varth - 24.08.2011
pawn Code:
new string[10];
format(string,sizeof(string),"Lololo1lo1lolo1");
string[strfind(string,"1")] = '_1';
return string;