Link to home
Start Free TrialLog in
Avatar of FearFactor_x
FearFactor_x

asked on

Converting a String arry of CAPS to Init Caps

hi Experts,
                What is the most efficient way to convert a string Array of all CAPS to init Caps..That is the first letter of each word {greater than 3 Characters ..} is capitalised  But the starting alphabet of the stirng is always capitalixed.. irrepective of whether it is 3 characters long or not.... For example..

1) I AM THE STRING WHICH IS TO BE CAPITALIZED..

should be converted into

Output : I am the String Which is to be Capitalized.

What is the most efficient way to do this..

Pls give me the most efficient way to approach this .

Thanx in Advance.

Regards,
newBie Programmer
Avatar of TimYates
TimYates
Flag of United Kingdom of Great Britain and Northern Ireland image

String tgt="THIS IS A TEST";
StringBuffer s=new StringBuffer(tgt.toLowerCase());
boolean raise=true;
for(int i=0; i<s.length(); ++i)
{   if(raise && !Character.isSpace(s.charAt(i)))
    {   s.setCharAt(i,Character.toUpperCase(s.charAt(i)));
        raise=false;
    }
    else if(!raise && Character.isSpace(s.charAt(i)))
    {   raise=true;
    }
}
String ns=new String(s);
That was from https://www.experts-exchange.com/questions/10235434/Converting-Strings-to-Title-case.html

There is also a class in the Apache Commons libraries to do this...  TextUtils class I think (but I can't be 100% sure)
ASKER CERTIFIED SOLUTION
Avatar of bobbit31
bobbit31
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
oops:

System.out.println(ret);