String Character Changing - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: String Character Changing (
/showthread.php?tid=517222)
String Character Changing -
Aerotactics - 03.06.2014
Alright, I'm having an issue with string character replacement:
Код:
if(!strcmp(input[i],"A") && input[i] != '\0'){input[i] = 'C'; continue;}
Picture 26 of these lines total, and they're in a for loop. Each line represents a letter of the alphabet, and a letter to replace it with.
Issue: When I enter a string such as "STRING", only the last letter is changed, instead of all of the characters.
Re: String Character Changing -
Vince - 03.06.2014
When you use input[i] it returns the entire string from that point onwards. For example:
pawn Код:
new input[6] = "hello";
printf("%s", input[1]);
//prints: ello
The proper way to compare a single character would be:
Note: single quotes.
But you may want to look at an implementation of rot13 or similar; 26 similar lines does not seem efficient at all.
Re: String Character Changing -
Aerotactics - 03.06.2014
Quote:
Originally Posted by Vince
When you use input[i] it returns the entire string from that point onwards. For example:
pawn Код:
new input[6] = "hello"; printf("%s", input[1]); //prints: ello
The proper way to compare a single character would be:
Note: single quotes.
But you may want to look at an implementation of rot13 or similar; 26 similar lines does not seem efficient at all.
|
While it might not be efficient, It's easy to read (but not easy on the eyes). Thanks for that correction, and I did some research on rot13. The difference is, you could change the character set in those 26 lines, with rot13, it's all the same key (it seems, from a short research period).
EDIT: I wrote this script as a sort of proof of concept to myself and to a friend, I might turn this into a stock to use for a wider range of jumbling