![]() ![]()
|
Home
PUBz Grafx Pax Tips & Trix Neo-Linx Neo-Talk Neo-Filez Search NeoDezign |
![]() |
You might find a situation where you need to convert user input text from lower case to upper case, (or upper to lower case), to maintain consistancy in your program. In the NeoBook\Samples folder there is a jewel of a script in the HangMan example game made by NeoSoft that does this quite effectively. This slick case convert routine uses some fancy string manipulation in a loop to get the job done. Let's pick it apart to learn how it works... |
... 'Prime the pump' giving X a value of 1 SetVar "[X]" "1" ...
Get the length of the text string
...
Initiate a loop until X equals the length of the text string
...
Pick apart the string one character at a time.
...
Search this Alphabet string for the match of C and store
...
Only act if the character C was found in the Alphabet string
...
Delete the character at position X
...
Pick out the uppercase character from the same position
...
Place this uppercase character into the same position
...
all done with this character - get outta here
...
Add 1 to the X loop to move on to the next character in the text string
...
Visual indicator
...
The bottom of the loop. If X is less than or equal to
Download an example PUB |