String newstr = Str.replaceAll(" "," ");
newstr = newstr.trim();
newstr = newstr.replaceAll(" "," ");
return newstr;
}
if (Str == null || Str.equals("")) {
return Str;
} else {
Str = ""+Str;
if( Flag == "l" || Flag == "L" )/*trim left side only*/
{
String RegularExp = "^[ ]+";
return Str.replaceAll(RegularExp,"");
}
else if( Flag == "r" || Flag == "R" )/*trim right side only*/
{
String RegularExp = "[ ]+$";
return Str.replaceAll(RegularExp,"");
}
else/*defautly, trim both left and right side*/
{
String RegularExp = "^[ ]+|[ ]+$";
return Str.replaceAll(RegularExp,"");
}
}
if (str == null || str.equals("")) {
return str;
} else {
//return leftTrim(rightTrim(str));
return str.replaceAll("^[ ]+|[ ]+$","");
}
}
if (str == null || str.equals("")) {
return str;
} else {
return str.replaceAll("^[ ]+", "");
}
}
if (str == null || str.equals("")) {
return str;
} else {
return str.replaceAll("[ ]+$", "");
}
}
System.out.println("leftTrim:" + leftTrim(" 123 123 123 ") + ":");
System.out.println("rightTrim:" + rightTrim(" 123 123 123 ") + ":");
System.out.println("trim:" + trim(" 123 123 123 ") + ":");
System.out.println("leftTrim:" + trims(" 123 123 123 ","l") + ":");
System.out.println("rightTrim:" + trims(" 123 123 123 ","r") + ":");
System.out.println("trim:" + trims(" 123 123 123 ","a") + ":");
}
if (str == null || str.equals("")) {
return str;
} else {
//return leftTrim(rightTrim(str));
return str.replaceAll("^[ ]+|[ ]+$","");
}
}
if (str == null || str.equals("")) {
return str;
} else {
return str.replaceAll("^[ ]+", "");
}
}
if (str == null || str.equals("")) {
return str;
} else {
return str.replaceAll("[ ]+$", "");
}
}
if (Str == null || Str.equals("")) {
return Str;
} else {
Str = ""+Str;
if( Flag == "l" || Flag == "L" )/*trim left side only*/
{
String RegularExp = "^[ ]+";
return Str.replaceAll(RegularExp,"");
}
else if( Flag == "r" || Flag == "R" )/*trim right side only*/
{
String RegularExp = "[ ]+$";
return Str.replaceAll(RegularExp,"");
}
else/*defautly, trim both left and right side*/
{
String RegularExp = "^[ ]+|[ ]+$";
return Str.replaceAll(RegularExp,"");
}
}
}
}