Page 1 of 1

LCase/UCase to work on .c

Posted: Sat Dec 27, 2008 5:24 am
by Mistrel
LCase and UCase only work on strings. What about chars? :?

Posted: Sat Dec 27, 2008 12:38 pm
by Fred
Debug UCase(Chr('a')) ?

Posted: Sat Dec 27, 2008 1:01 pm
by Mistrel
Is it possible to change the case of a unicode character without changing it to a string? From a performance perspective I parse using character arrays because it deals purely with integers. For a string search I convert the input string to lower case before running a comparison.

I think this operation would be faster if I could change the case of only the characters I parse. But this only seems feasible without having to change the character to a string first.

Posted: Sat Dec 27, 2008 1:02 pm
by Trond
No, but you can always change it back with Asc().

Posted: Sat Dec 27, 2008 1:04 pm
by Mistrel
Caught me while I was editing, Trond. See my clarification. Maybe you can provide a different solution.

Posted: Sat Dec 27, 2008 1:19 pm
by Trond
You could have converted the characters to lowercase before putting them into the array if case is not significant.

Posted: Sat Dec 27, 2008 3:36 pm
by AND51
Note, that the ASCII-characters have a special offset.
Between 'A' and 'a' are 32 others characters:

Code: Select all

Debug 'a'-'A'
Debug 'b'-'B'
; and so on...
So you can easily add or substract 32 to each .c-variable to turn it into upper or lower case.

With pointer you can even scan whole strings.

Posted: Sat Dec 27, 2008 8:51 pm
by Trond
AND51 wrote:Note, that the ASCII-characters have a special offset.
Between 'A' and 'a' are 32 others characters:

Code: Select all

Debug 'a'-'A'
Debug 'b'-'B'
; and so on...
So you can easily add or substract 32 to each .c-variable to turn it into upper or lower case.
Remember to check if it's actually a letter first. Subtracting 32 from a symbol like backspace will not create a "lower-case backspace".

Posted: Sat Dec 27, 2008 11:58 pm
by flaith
Or with XOR

Code: Select all

a.c = Asc("A")  ; = 65  ;1000001
; or
;a.c = Asc("a")  ; = 97  ;1100001

Debug Chr(a)

b.c = a ! %00100000

Debug Chr(b)

Posted: Sun Dec 28, 2008 6:07 am
by Mistrel
Excellent! I had no idea about this significant offset. Thank you. :)

Posted: Sun Dec 28, 2008 10:01 pm
by flaith
you're welcome :D

Posted: Sat Jan 03, 2009 7:33 pm
by Trond
Also it doesn't work for ß and such characters.