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
High-roller
 
iPLEOMAX's Avatar
 
Join Date: Mar 2011
Location: AE
Posts: 1,290
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, 10:30 AM   #2
Wesley221
High-roller
 
Wesley221's Avatar
 
Join Date: Apr 2011
Posts: 2,736
Reputation: 714
Default Re: Inserting a character into a string.

Use str_replace.

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

Code:
new string[10];
format(string,sizeof(string),"Lololo1lo1lolo1");
string[strfind(string,"1")] = '_1';
return string;
__________________
(RETIRED)
=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 23/02/2011 11:10 PM
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 04:19 PM.


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