SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Help Archive

Thread Tools Display Modes
Old 24/08/2011, 11:21 AM   #1
iPLEOMAX's Avatar
Join Date: Mar 2011
Location: AE
Posts: 1,274
Reputation: 739
Default Inserting a character into a string.

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 ?
Goodbye SA-MP.
iPLEOMAX is offline  
Old 24/08/2011, 11:30 AM   #2
Wesley221's Avatar
Join Date: Apr 2011
Posts: 2,729
Reputation: 714
Default Re: Inserting a character into a string.

Use str_replace.

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
Wesley221 is offline  
Old 24/08/2011, 11:35 AM   #3
=WoR=Varth's Avatar
Join Date: Apr 2011
Location: Indonesia
Posts: 2,010
Reputation: 133
Default Re: Inserting a character into a string.

new string[10];
string[strfind(string,"1")] = '_1';
return string;
=WoR=Varth is offline  

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
MYSQL Getting and inserting AlExAlExAlEx Help Archive 13 24/02/2011 12:10 AM
Loading string from a file and inserting it into other string Ivan_Pantovic Help Archive 0 06/02/2011 08:22 PM
About inserting a filterscript into my GM. Apply Help Archive 1 12/05/2010 12:06 PM
How to make pawn to ignore % character in string? Dujma Help Archive 4 25/11/2009 09:48 PM
Help with inserting... lukica Help Archive 3 22/03/2009 09:44 AM

All times are GMT. The time now is 02:31 AM.

Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.