class Demo
{
public static void main(String[] args)
{
String s1 = " abc abc ";
String s2 = "";
sop(s1);
s2 = trim(s1);
sop(s2);
}
public static void sop(Object obj)
{
System.out.println(obj);
}
public static String trim(String str)
{
String s = "";
char[] chs = str.toCharArray();
int len_begin = 0;
int len_end = chs.length;
while(chs[len_begin] ==' ')
{
len_begin++;
}
while(chs[len_end] == ' ')
{
len_end--;
}
s = new String(chs,len_begin,(len_end - len_begin));
return s;
}
}
编译没有问题,但是在运行时候报错: |
|