Raised This Month: $ Target: $400
 0% 

[HELP]edit content from string (strbreak)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
seriousspot
BANNED
Join Date: Mar 2013
Location: Lithuania / Norway
Old 07-20-2013 , 19:28   [HELP]edit content from string (strbreak)
Reply With Quote #1

for example i got queried sql result from row data:

Quote:
2440 0 2 5 3 0 0 0 0 0 0 0 0
how do i edit only 2440 and set as variable(i can set value what ever i want to, this supposed to be only numbers) without touching other values

lets say i have successfully edited 2440 to 3444, and whole string should look like:

Quote:
3444 0 2 5 3 0 0 0 0 0 0 0 0
(with spaces as original)

other contents rest same

Last edited by seriousspot; 07-20-2013 at 19:31.
seriousspot is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 07-21-2013 , 17:27   Re: [HELP]edit content from string (strbreak)
Reply With Quote #2

You could break it by spaces with strbreak(), turn the string into a number with str_to_num(), edit the number and then add the two parts together again using formatex(%d %s, first_number, rest_of_string)

This example reproduces your example:
Code:
    new left[32], right[128], test[128] = "2440 0 2 5 3 0 0 0 0 0 0 0 0";         strbreak(test, left, 31, right, 127);         new leftnum = str_to_num(left);     leftnum += 1004;         formatex(test, 127, "%d %s", leftnum, right);         server_print("%s", test);
Output:
Code:
3444 0 2 5 3 0 0 0 0 0 0 0 0
If you want to break it further you could use strbreak() or even parse() if you want to break most of it apart.

Last edited by Black Rose; 07-21-2013 at 17:37.
Black Rose is offline
seriousspot
BANNED
Join Date: Mar 2013
Location: Lithuania / Norway
Old 07-23-2013 , 15:08   Re: [HELP]edit content from string (strbreak)
Reply With Quote #3

Quote:
Originally Posted by Black Rose View Post
You could break it by spaces with strbreak(), turn the string into a number with str_to_num(), edit the number and then add the two parts together again using formatex(%d %s, first_number, rest_of_string)

This example reproduces your example:
Code:
    new left[32], right[128], test[128] = "2440 0 2 5 3 0 0 0 0 0 0 0 0";         strbreak(test, left, 31, right, 127);         new leftnum = str_to_num(left);     leftnum += 1004;         formatex(test, 127, "%d %s", leftnum, right);         server_print("%s", test);
Output:
Code:
3444 0 2 5 3 0 0 0 0 0 0 0 0
If you want to break it further you could use strbreak() or even parse() if you want to break most of it apart.

Thank you, thats exact what i need, but found it earlier, so thanks for lightweight code, ill improve mine with this
seriousspot is offline
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 06:28.


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