Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Changing case in strings (https://forums.graalonline.com/forums/showthread.php?t=13229)

entravial 09-29-2001 03:00 AM

Changing case in strings
 
~AlphaFlame~

How would one go about changing the case of letters in a string? Say you have a string "this.letters" being set letter by letter... and you want certain letters to be capitalized. Script example:

if (playerchats){
for (this.i=0;this.i<strlen(#c);this.i++){
if (!strequals(#e(this.i+3,1,#c),h)){
setstring letters,#s(letters) #e(this.i+3,1,#c);
} else {
setstring letters,#s(letters) capitlization thing here;
}
}

Now, lets say I wanted all the H's to be capitalized. How would I go about doing that where the blue text is? My idea was to use the new ascii command, and add/subtract the correct value from lowercase to uppercase, but then I'd need to know how to check the ascii of that particular letter...

Hopefully you people can understand that :o

KJS 09-29-2001 03:28 AM

A - Z is ascii 65 - 90
a - z is ascii 97 - 122

hopefully that helps you on what your asking

entravial 09-29-2001 03:36 AM

~AlphaFlame~

Unless you can find a way to check the letter's ascii, no it doesn't help. And I really don't feel like typing...
if (ascii(57)){
setstring letters,ascii(97);
}
or whatever a thousand times.

KJS 09-29-2001 03:39 AM

Quote:

Originally posted by entravial
~AlphaFlame~

Unless you can find a way to check the letter's ascii, no it doesn't help. And I really don't feel like typing...
if (ascii(57)){
setstring letters,ascii(97);
}
or whatever a thousand times.

NPC Code:

if(ascii(this.lookfor))
setstring letters,ascii(this.lookfor+32);



it would be something like that

entravial 09-29-2001 04:16 AM

~AlphaFlame~

I know that would work, but then how would you assign the letters to this.lookfor? :p

KJS 09-29-2001 04:19 AM

just replace it with whatever you want it to be replaced with (if it changes then set it once they change it..

so like if you want it to capitalize h when the player says

cap h

then set the this.lookfor when they say that...

otherwise just replace it with whatever letter you want to capitalize)

entravial 09-29-2001 04:23 AM

~AlphaFlame~

So, that means I would have to do this.

setstring this.lookfor,#e(the letter thingy);
setstring letters,#s(letters) ascii(strtofloat(#s(this.lookfor))+30);

... Hmm... thanks KJL. Never would of thought of that myself.

KJS 09-29-2001 04:26 AM

looks for would have to be the number of the letter your looking for....

like so if it was

a

this.looksfor would have to be 97


All times are GMT +2. The time now is 11:59 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.