I've read a lot about how some users "hate" the String Object and prefer to use char arrays when possible. So I'm trying to become more proficient in using char arrays to store my strings.
Question:
What would the best way be to change the case of a string stored as a char array to Upper Case.
I see that there are already methods like strcmp and strcpy to perform other tasks on char arrays.
I can't seem to find something for changing case ( as exists for the String Object ).
For the ASCII alphas, bit 5 is the difference in case.
1 loop the length of the buffer with break on NULL, if the ASCII is not alpha-only then with a range check ( data & 0xDF >= 'A' ) && ( data & 0xDF <= 'Z' ) and either set or clear bit 5.... make the state an arg and 1 function could do both change to upper or lower case.
That worked good !
I like it.
Thanks for helping me !
Bob
GoForSmoke:
For the ASCII alphas, bit 5 is the difference in case.
1 loop the length of the buffer with break on NULL, if the ASCII is not alpha-only then with a range check ( data & 0xDF >= 'A' ) && ( data & 0xDF <= 'Z' ) and either set or clear bit 5.... make the state an arg and 1 function could do both change to upper or lower case.
char array strings are so simple and easy to get at I have to wonder at the use of String objects that 'protect' the data from the programmer. What kind of programmers does data need protection from? Can't be -good- ones!
Below is how I tested your suggestion to UpCase a string.
Works good.
Doesn't look very good.
Can you suggest how I can get rid of the for loop and replace it with a while (myString != NULL) ?
I don't see how to step through the buffer without an index like "i".
Thanks.
Bob W.
char myString[] = "Hello";
void setup() {
Serial.begin(9600);
for (int i = 0; i < 100; i++ ) // 100 set arbitrarily and excessively large
{
if ( myString[i] == NULL ) break;
myString[i] = myString[i] & 0b11011111;
}
Serial.print( &myString[0] );
GoForSmoke:
For the ASCII alphas, bit 5 is the difference in case.
1 loop the length of the buffer with break on NULL, if the ASCII is not alpha-only then with a range check ( data & 0xDF >= 'A' ) && ( data & 0xDF <= 'Z' ) and either set or clear bit 5.... make the state an arg and 1 function could do both change to upper or lower case.