Go Down

Topic: Converting char to upper case (Read 4150 times) previous topic - next topic

Atalanttore

Hi

I need to convert a char to upper case.
I was trying char.toUpperCase(), but this function doesn't work for chars.

Is there an UpperCase function for chars?


Regards,
Atalanttore

Senso

Yes, using this std c function:
int toupper    (    int     __c )

http://www.nongnu.org/avr-libc/user-manual/group__ctype.html#ga924ed052807e23cfa160d5f171cf5e2a

liudr

char one_char='f';
one_char=one_char-'a'-'A';

This is when you are sure the one_char is in lower case. Otherwise, do if statement.

bperrybap


char one_char='f';
one_char=one_char-'a'-'A';

This is when you are sure the one_char is in lower case. Otherwise, do if statement.


But if you want to get down and dirty and assume ASCII and that the values are always
letters vs any possible character, and not use the ctype functions, then simply mask off
bit 5.

i.e.
Code: [Select]

upper_charvalue = charvalue & ~(0x20);


It won't matter if the charvalue is upper or lower case. But it will trash characters
that are not letters.

If you use the toupper() function, it will only convert lower case characters to upper case
and leave other characters alone.

--- bill

robtillaart

Quote
one_char=one_char-'a'-'A';


must be a +

one_char = one_char - 'a' + 'A';

----

Include <ctype.h>   -->  - http://www.nongnu.org/avr-libc/user-manual/group__ctype.html -

Then you have "all" char manipulators

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

liudr


robtillaart

Quote
parentheses 

Recently I read a product description of a calculator that used different colors for matching parentheses. Quite functional!
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Atalanttore


Recently I read a product description of a calculator that used different colors for matching parentheses. Quite functional!


Good idea. I would like an editor/IDE, which uses different colors for matching parentheses.

liudr



Recently I read a product description of a calculator that used different colors for matching parentheses. Quite functional!


Good idea. I would like an editor/IDE, which uses different colors for matching parentheses.


They at least indicate the parentheses when you have cursor on one of them.

Go Up