Raised This Month: $ Target: $400
 0% 

Solved Replace in a String that Contains Repeated Chars


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
asdian
Member
Join Date: Sep 2016
Location: Indonesia
Old 07-20-2022 , 10:01   Re: Replace in a String that Contains Repeated Chars
Reply With Quote #7

Quote:
Originally Posted by damage220 View Post
It is much clearer now. So, you need only to change the last character. +ARUKARI- has already posted an answer, you need to edit last cell in an array.
PHP Code:
szChoosenCos[strlen(szChoosenCos) - 1] = 'w'
String is an array of characters terminated with null byte. You can replace
PHP Code:
equal(szChoosenCos[strlen(szChoosenCos)-1], "w"
with
PHP Code:
if(szChoosenCos[strlen(szChoosenCos)-1] == 'w'// note single quote 
Then, if you want to delete the suffix, you should terminate the string with null byte.
PHP Code:
szChoosenCos[strlen(szChoosenCos) - 1] = '^0'
You can also apply suffix with formatex which may be better depending on your needs.
PHP Code:
formatex(szCheckcharsmax(szCheck), "models/costume/%s_w.mdl"szChoosenCos
Or even create a matrix with all the models to speed things up.
PHP Code:
new const models[][][] = {
    {
"models/costume/model1_m.mdl""models/costume/model1_w.mdl"},
    {
"models/costume/model2_m.mdl""models/costume/model2_w.mdl"},
    {
"models/costume/model3_m.mdl""models/costume/model3_w.mdl"},
};

// get first man model
models[0][0
so there's no need to use replace native ?

also if i want to delete suffix with underscore symbol is it just change
Quote:
PHP Code:
szChoosenCos[strlen(szChoosenCos) - 1] = '^0'
to
PHP Code:
szChoosenCos[strlen(szChoosenCos) - 2] = '^0'
?

Last edited by asdian; 07-20-2022 at 10:10. Reason: forgot question
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 00:19.


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