Re: Help converting a string





Ian Shef wrote On 11/08/06 14:54,:
"Rhino" <no.offline.contact.please@xxxxxxxxxx> wrote in
news:eit8kf$ifm$1@xxxxxxxxxxxxxxx:


"Shay" <SSwygert@xxxxxxxxx> wrote in message
news:1162993442.918861.216370@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

I need help with converting all lowercase letters in a string to
uppercase letters and viceversa. For example, Alb34ErT will be
converted to aLB34eRt.

I know to use something like:

String sentence;
sentence = "ThIs 4th SenTEnce NEeds IO cHaNge12.";
sentence.toLowerCase();
System.out.println(sentence.toUpperCase());

But I can't figure out how to do both at once to the same string. HELP!


I think the problem is that you are trying to convert the entire
sentence in a single statement. You need to convert each letter
individually. For example, look at the first character and see if it is
upper case or lower case: if it is upper case, change it to lower case
and if it is lower case, change it to upper case. Naturally, if it is a
digit or punctuation character, don't change the case at all. Simply do
the same logic on each character in turn until all have been examined
and changed or left alone, as the case may be.

--
Rhino


However, there is no method to determine whether an individual character is
upper or lower case. [...]

What's wrong with the isLowerCase() and isUpperCase()
methods of java.lang.Character?

--
Eric.Sosman@xxxxxxx

.



Relevant Pages

  • Re: Help converting a string
    ... uppercase letters and viceversa. ... For example, Alb34ErT will be ... String sentence; ... if it is upper case, change it to lower case and if it is lower case, ...
    (comp.lang.java.help)
  • Re: Help converting a string
    ... String sentence; ... But I can't figure out how to do both at once to the same string. ... upper case or lower case: if it is upper case, ... digit or punctuation character, don't change the case at all. ...
    (comp.lang.java.help)
  • Re: Combo box auto populate problem with CAPS
    ... character in upper case, inserted into the middle of the string of the found ... The choices in the combo box may be any combination: Upper case, ... find a correct match. ... Dirk Goldgar, MS Access MVP ...
    (microsoft.public.access.formscoding)
  • Re: Is there any way to say ignore case with "in"?
    ... the same character, as the character is already in lower case. ... Instead of 15 exceptions to the rule, conversion to upper has only 5 ... The other effect would be conflating physics' Angstron unit and Kelvin unit signs with ring-a and K. Applicaton programmers beware. ...
    (comp.lang.python)
  • Re: Exercise 7-1
    ... Your indentation is inconsistent and doesn't correspond either to the ...     int c; ... to upper case if it's invoked as "upper", ... while loop to read each character from stdin, ...
    (comp.lang.c)