Inserting a character into a string.
#1

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 ?
Reply
#2

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
Reply
#3

pawn Code:
new string[10];
format(string,sizeof(string),"Lololo1lo1lolo1");
string[strfind(string,"1")] = '_1';
return string;
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)