SA-MP Forums Archive
Capitalizing an entire string. - 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: Capitalizing an entire string. (/showthread.php?tid=393268)



Capitalizing an entire string. - Dennis_Smith - 17.11.2012

I'm trying to capitalize a whole string. However, I could only find toupper which does one letter. If anyone can find me the function to do that, I'd really appreciate it.


Re: Capitalizing an entire string. - Niko_boy - 17.11.2012

loop + to upper
say if u have a string names string
then to capitalize it try this ->
pawn Код:
new newstring[256];//or any size larger may be?
for( new i, c = strlen(string); i < c; i++ )
{
    format(newstring,sizeof(newstring),"%s%c",newstring,toupper(string[i]));
}
//use newstring now it must be capitalized ..!



Re: Capitalizing an entire string. - Stylock - 17.11.2012

Quote:
Originally Posted by Niko_boy
Посмотреть сообщение
loop + to upper
say if u have a string names string
then to capitalize it try this ->
pawn Код:
new newstring[256];//or any size larger may be?
for( new i, c = strlen(string); i < c; i++ )
{
    format(newstring,sizeof(newstring),"%s%c",newstring,toupper(string[i]));
}
//use newstring now it must be capitalized ..!
You don't need to create a new string for that. You can just do:
pawn Код:
for(new i, len = strlen(string); i < len; ++i)
{
    string[i] = toupper(string[i]);
}