By this method you can easily convert your 1st latter to caps , if 1st later already in caps then no changes happen string always rerun with 1st latter caps
public static String get1stLatterCaps(String mString)
{
String mFinalStr="";
try {
if (mString.length() > 0) {
String mTempString = ("" + mString.charAt(0)).toUpperCase();
// Log.e(" mTempString ", " mTempString : " + mTempString);
// Log.e(" mString.charAt(0) ", " mString.charAt(0) : " + mString.charAt(0));
if (mString.length() > 1) {
mFinalStr = mTempString + mString.substring(1, mString.length());
// Log.e(" mStr ", " mStr : " + mFinalStr);
} else {
mFinalStr = mTempString;
// Log.e(" mStr ", " mStr : " + mFinalStr);
}
} else {
Log.e(" empty String ", " empty String : ");
}
Log.e("mFinalStr ", " mFinalStr : " +mFinalStr);
//mString.replace(""+mString.charAt(0),mTempString);
}catch (Exception ex)
{
ex.printStackTrace();
}
return mFinalStr;
}
public static String get1stLatterCaps(String mString)
{
String mFinalStr="";
try {
if (mString.length() > 0) {
String mTempString = ("" + mString.charAt(0)).toUpperCase();
// Log.e(" mTempString ", " mTempString : " + mTempString);
// Log.e(" mString.charAt(0) ", " mString.charAt(0) : " + mString.charAt(0));
if (mString.length() > 1) {
mFinalStr = mTempString + mString.substring(1, mString.length());
// Log.e(" mStr ", " mStr : " + mFinalStr);
} else {
mFinalStr = mTempString;
// Log.e(" mStr ", " mStr : " + mFinalStr);
}
} else {
Log.e(" empty String ", " empty String : ");
}
Log.e("mFinalStr ", " mFinalStr : " +mFinalStr);
//mString.replace(""+mString.charAt(0),mTempString);
}catch (Exception ex)
{
ex.printStackTrace();
}
return mFinalStr;
}
No comments:
Post a Comment