Raised This Month: $32 Target: $400
 8% 

Solved Replace in a String that Contains Repeated Chars


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
asdian
Member
Join Date: Sep 2016
Location: Indonesia
Old 07-20-2022 , 04:24   Replace in a String that Contains Repeated Chars
Reply With Quote #1

*edit
i am making a costume plugin. some costumes has name suffix of "w" for women and "m" for men. to make it simple im trying to make a code that detects what character is choosed (w/m) then random costume will bound to that chara based on gender. because the costumes are so many, i'm facing this problem. the costume is named "y19s4coswolfw" for women. it has "y19s4coswolfm" counterpart for men. if men is choosen, costume should be "y19s4coswolfm" whereas for women it should be "y19s4coswolfw". im thinking to simply just rename the suffix, which is "w" to "m" for men. the code below.

Code:
if(g_choosensex[id] == 1 /*men*/ && equal(szChoosenCos[strlen(szChoosenCos)-1], "w") /*if choosen cos is have "w" suffix*/)
{
        // replace char
	replace(szChoosenCos, charsmax(szChoosenCos), "w", "m")
			
	new szCheck[64]
	formatex(szCheck, charsmax(szCheck), "models/costume/%s.mdl", szChoosenCos)
	
        // if doesn't exists then delete any suffix
	if(!file_exists(szCheck))
	{
		if(equal(szChoosenCos[strlen(szChoosenCos)-2], "_m")) replace(szChoosenCos, charsmax(szChoosenCos), szChoosenCos[strlen(szChoosenCos)-2], "")
		if(equal(szChoosenCos[strlen(szChoosenCos)-1], "m")) replace(szChoosenCos, charsmax(szChoosenCos), szChoosenCos[strlen(szChoosenCos)-1], "")
	}
}
but the result of renaming is
Code:
y19s4cosmolfw
which means the first 'w' from "y19s4coswolfw" is replaced instead the suffix 'w' i want.

Also i've tried :
Code:
replace(sz, charsmax(sz), sz[strlen(sz)-1], "m")
which is in my understanding will directed to the suffix but still gave same "y19s4cosmolfw" result.

How can i solve this?

Last edited by asdian; 08-14-2022 at 08:58. Reason: to make it clearer
asdian is offline
 



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 17:43.


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