首页 > 其他 > 详细

去除字符串两端的空白

时间:2017-11-02 19:52:40      阅读:216      评论:0      收藏:0      [点我收藏+]

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

定义两个变量,从头到尾定义
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);

 

去除字符串两端的空白

原文:http://www.cnblogs.com/Candicecl/p/7773726.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!