> I want write an function to convert the abc_def_gh to AbcDefGh.
>
[quoted text clipped - 18 lines]
> name.replaceAll("[a-z]{1}_", "what here?"), but I can't write the
> second arguments.
On Fri, 14 Sep 2007 16:41:06 GMT, Thomas Fritsch
<i.dont.like.spam@invalid.com> wrote, quoted or indirectly quoted
someone who said :
> className.append(needUpperCase ? Character.toUpperCase(c) : c);
> needUpperCase = false;
You might go for efficient code just for a learning exercise, but it
the real world, you would leave this method be unless it proved to be
a bottleneck.
toUpperCase is a hairy routine with all manner of coded cultural lore
on how caps are done for various symbol sets. If you are just dealing
with English, you can write a much simpler version that goes like
this:
static char toUpperCase( char c )
{
return 'a' <= c && c <= 'z' ? (char)( c + ('A'-'a')) : c;
}

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Roedy Green - 19 Sep 2007 20:02 GMT
On Wed, 19 Sep 2007 16:43:48 GMT, Roedy Green
<see_website@mindprod.com.invalid> wrote, quoted or indirectly quoted
someone who said :
>toUpperCase is a hairy routine with all manner of coded cultural lore
>on how caps are done for various symbol sets. If you are just dealing
[quoted text clipped - 5 lines]
> return 'a' <= c && c <= 'z' ? (char)( c + ('A'-'a')) : c;
> }
The code for all four methods is part of StringTools. See
http://mindprod.com/products1.html#COMMON11
/**
* Quick replacement for Character.toLowerCase for use with
English-only. It
* does not deal with accented characters.
*
* @param c character to convert
*
* @return character converted to lower case
*/
static char toLowerCase( char c )
{
return 'A' <= c && c <= 'Z' ? (char) ( c + ( 'a' - 'A' ) ) :
c;
}
/**
* Quick replacement for Character.toLowerCase for use with
English-only. It
* does not deal with accented characters.
*
* @param s String to convert
*
* @return String converted to lower case
*/
static String toLowerCase( String s )
{
final char[] ca = s.toCharArray();
final int length = ca.length;
boolean changed = false;
// can't use for:each since we need the index to set.
for ( int i = 0; i < length; i++ )
{
final char c = ca[ i ];
if ( 'A' <= c && c <= 'Z' )
{
// found a char that needs conversion.
ca[ i ] = (char) ( c + ( 'a' - 'A' ) );
changed = true;
}
}
// give back same string if unchanged.
return changed ? new String( ca ) : s;
}
/**
* Quick replacement for Character.toUpperCase for use with
English-only. It
* does not deal with accented characters.
*
* @param c character to convert
*
* @return character converted to upper case
*/
static char toUpperCase( char c )
{
return 'a' <= c && c <= 'z' ? (char) ( c + ( 'A' - 'a' ) ) :
c;
}
/**
* Quick replacement for Character.toUpperCase for use with
English-only. It
* does not deal with accented characters.
*
* @param s String to convert
*
* @return String converted to upper case
*/
static String toUpperCase( String s )
{
final char[] ca = s.toCharArray();
final int length = ca.length;
boolean changed = false;
// can't use for:each since we need the index to set.
for ( int i = 0; i < length; i++ )
{
final char c = ca[ i ];
if ( 'a' <= c && c <= 'z' )
{
// found a char that needs conversion.
ca[ i ] = (char) ( c + ( 'A' - 'a' ) );
changed = true;
}
}
// give back same string if unchanged.
return changed ? new String( ca ) : s;
}

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com