class Demo
{
public static void sop(String str)
{
System.out.println(str);
}
public static void main(String[] args)
{
String s = " afssg sdgsd ";
sop("("+s+")");
s = myTrim(s);
sop("("+s+")");
}
public static String myTrim(String str)
{
int pos = 0,end = str.length()-1;
while(pos<=end && str.charAt(pos)==' ')
pos++;
while(pos<=end && str.charAt(end)==' ')
end--;
return str.substring(pos,end+1);
}
}
|
|