Re: Help converting a string
- From: Eric Sosman <Eric.Sosman@xxxxxxx>
- Date: Wed, 08 Nov 2006 15:11:13 -0500
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
.
- Follow-Ups:
- Re: Help converting a string
- From: Ian Shef
- Re: Help converting a string
- References:
- Help converting a string
- From: Shay
- Re: Help converting a string
- From: Rhino
- Re: Help converting a string
- From: Ian Shef
- Help converting a string
- Prev by Date: Re: Help converting a string
- Next by Date: Re: Help converting a string
- Previous by thread: Re: Help converting a string
- Next by thread: Re: Help converting a string
- Index(es):
Relevant Pages
|