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, 10:21 AM   #1
iPLEOMAX's Avatar
Join Date: Mar 2011
Location: AE
Posts: 1,250
Reputation: 746
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, 10:30 AM   #2
Wesley221's Avatar
Join Date: Apr 2011
Posts: 1,564
Reputation: 715
Default Re: Inserting a character into a string.

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

pawn Code:
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
Loading string from a file and inserting it into other string Ivan_Pantovic Help Archive 0 06/02/2011 07:22 PM
About inserting a filterscript into my GM. Apply Help Archive 1 12/05/2010 11:06 AM
How to make pawn to ignore % character in string? Dujma Help Archive 4 25/11/2009 08:48 PM
Help with inserting... lukica Help Archive 3 22/03/2009 08:44 AM

All times are GMT. The time now is 03:25 PM.

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