Case sensitive strings

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Metallic-Red

Case sensitive strings

Post by Metallic-Red »

I've made a simple DOS style interface for my OS that can process commands like "cls" and "ver" but I also want it to be able to process these commands no matter what case they are in. For example, I want all of the following to do the same thing:

CLS
cls
Cls
clS
etc.

The command is stored in a buffer and is compared with a command string:

cmdCls DB "cls", 0x00

Is there an easy way of eliminating the case sensitivity?
richie

Re:Case sensitive strings

Post by richie »

Yes. Just convert your read command string to lower case. Then you can compare it.
Example:
If the user types "cLs" you convert it to lower case an it gets "cls". Then you can compare it to cmdCls.

The conversion to lower case can be done in a loop:
For every char test if it is between 'A' and 'Z'. If so you add ('a' - 'A') to this char. ('a' = 97, 'A' = 65). All other chars you leave as they are. To understand why this conversion works look at some ASCII table.
Post Reply