Strange String replacement...
Hello,
I'm not a C programmer for a long time (more than 8 years) and I don't know much more about the strings functions that we have today aside the basic ones...
I want to do some search/calculate/replace in a string but I don't know the functions well aside do in the hard code way, char by char... which I think should exist a better way to solve...
here's what I need:
I have a big string, and inside we have N times like this code:
"origin" "-264 -256 16"
the numbers aren't the same of course, and I need to replace all these origins in Z axis plus 15... (in this case, I need to add 15 to the 16 value)
so I need to turn that string into:
"origin" "-264 -256 31"
it's not always 2 chars, could be even like:
"origin" "-264 -256 1234"
but in all the cases is just add 15 to the Z axis to fix a bug.
so we need to get the number between the third space and third " after the string origin, convert to number, add 15, and replace in the string.
this must be done to all origins found on the string.
any ideas?
thanks a lot!
that solution will not work, here a new one!
well, I realize that I can't change all origins, because I'll cause problems to other classes....
so I can only change info_player_deathmatch and info_player_start classes
so here the new pseudocode to solve this:
Code:
set working = 1;
while working == 1 {
if "{" not found{
set working = 0;
else{
subs = GetSubstring(String, first {, first });
Str1 = GetSubstring (String[0], subs[0]);
Str2 = GetSubstring (subs[size],String[size]);
if found (info_player_deathmatch || info_player_start) in subs {
find "origin" location;
posA = find 3rd space after origin location;
posB = find next " after posA;
Subs1 = GetSubstring (subs[0],posA);
Subs2 = GetSubstring (posB,subs[size]);
num = GetSubstring (posA, posB);
ToNumber(num) += 15;
subs = Subs1 + num + Subs2;
ReplaceAll (subs, {, [);
ReplaceAll (subs, }, ]);
}
}
}
ReplaceAll (String, [, {);
ReplaceAll (String, ], });
any inputs?