去除字符串两端的空格

class SrringTest
{
	string sop(String str)
	{
		System.out.println(str);
	}
	public stctic void main(String [] args)
	{
		String s = "    abc de     ";
		
		sop("("+s”)");
		s = myTrim(s);
		sop("("+s")");
	}

	public static String myTyim(String str)
	{
		int start = 0,end = str.length() - 1;
		
		while(start<=end && str.charAt(start) == ' ')
			start++;
		
		while(start<=end && str.charAt(end) == ' ')
			end--;
		
		return str.substring(start,end+1);
	}
}

你可能感兴趣的:(去除字符串两端的空格)