Raised This Month: $ Target: $400
 0% 

Replace specific characters in a string?


Post New Thread Reply   
 
Thread Tools Display Modes
BaD CopY
Senior Member
Join Date: Oct 2014
Location: Home
Old 07-24-2018 , 14:19   Re: Replace specific characters in a string?
Reply With Quote #11

I tried to replace character but by using replace function my string is replaced with a character:

PHP Code:
new String[] = "abcd";

new 
len strlen(String);

for(new 
0leni++
    
replace(StringlenString[i], "i");

console_print(0"String: %s"String); 
Output:

Code:
String: i

Last edited by BaD CopY; 07-24-2018 at 14:24.
BaD CopY is offline
Send a message via Yahoo to BaD CopY Send a message via Skype™ to BaD CopY
Ghosted
Veteran Member
Join Date: Apr 2015
Location: Georgia
Old 07-24-2018 , 14:22   Re: Replace specific characters in a string?
Reply With Quote #12

Quote:
Originally Posted by BaD CopY View Post
I tried to replace character but by using replace function my string is replaced with a character:

PHP Code:
new String[] = "abcd";

new 
len strlen(String);

for(new 
0leni++
    
replace(StringlenString[i], "i");

console_print(0"String: %s"String"); 
Output:

Code:
String: i
What actually do you want?
__________________

[MOD] CS Weapon Mod V1.7.1
[MM] MetaMod-C V1.0
[MOD] CS NPC Mod (5%)


Probably Left AM
Ghosted is offline
BaD CopY
Senior Member
Join Date: Oct 2014
Location: Home
Old 07-24-2018 , 14:23   Re: Replace specific characters in a string?
Reply With Quote #13

https://forums.alliedmods.net/showth...=309093&page=3

So I'm trying to make this and I'm on good way
BaD CopY is offline
Send a message via Yahoo to BaD CopY Send a message via Skype™ to BaD CopY
Natsheh
Veteran Member
Join Date: Sep 2012
Old 07-24-2018 , 15:12   Re: Replace specific characters in a string?
Reply With Quote #14

Quote:
Originally Posted by BaD CopY View Post
I tried to replace character but by using replace function my string is replaced with a character:

PHP Code:
new String[] = "abcd";

new 
len strlen(String);

for(new 
0leni++
    
replace(StringlenString[i], "i");

console_print(0"String: %s"String); 
Output:

Code:
String: i
replace(String, charsmax(String), String, "i");

You are replacing a string and not a character.


If you want to replace a character
Use

PHP Code:
new String[] = "abcd";

new 
len strlen(String);

for(new 
0Str[2]; leni++)
{
    
Str[0] = String[i];
    
replace(Stringcharsmax(String), Str"i");
    
// Or
    
String[i] = 'i';
}

console_print(0"String: %s"String); 

Output:

String: iiii
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 07-24-2018 at 15:28.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-24-2018 , 21:12   Re: Replace specific characters in a string?
Reply With Quote #15

Quote:
Originally Posted by BaD CopY View Post
https://forums.alliedmods.net/showth...=309093&page=3

So I'm trying to make this and I'm on good way
This thread has absolutely nothing to do with what you are requesting. Please keep your discussion of your topic in your own topic now that we know what you want.
__________________
fysiks is offline
BaD CopY
Senior Member
Join Date: Oct 2014
Location: Home
Old 07-25-2018 , 12:02   Re: Replace specific characters in a string?
Reply With Quote #16

Quote:
Originally Posted by Natsheh View Post
replace(String, charsmax(String), String, "i");

You are replacing a string and not a character.


If you want to replace a character
Use

PHP Code:
new String[] = "abcd";

new 
len strlen(String);

for(new 
0Str[2]; leni++)
{
    
Str[0] = String[i];
    
replace(Stringcharsmax(String), Str"i");
    
// Or
    
String[i] = 'i';
}

console_print(0"String: %s"String); 

Output:

String: iiii
Thank you
BaD CopY is offline
Send a message via Yahoo to BaD CopY Send a message via Skype™ to BaD CopY
Reply



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

Forum Jump


All times are GMT -4. The time now is 14:57.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode