chen_li

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::

需求: 去除字符串两端的空白
思路:

定义两个变量,从头到尾定义
1、一个变量从头开始判断++
2、一个变量从尾开始判断--

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

 

posted on 2017-11-02 18:40  chen_li  阅读(274)  评论(0)    收藏  举报