Chinaunix首页 | 论坛 | 博客
  • 博客访问: 151891
  • 博文数量: 34
  • 博客积分: 2010
  • 博客等级: 大尉
  • 技术积分: 346
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-19 09:53
文章分类

全部博文(34)

文章存档

2011年(1)

2009年(33)

我的朋友

分类: Java

2009-09-15 15:28:29

public class Test {

 public static void main(String[] args) {
  String s = "GET             /index.html HTTP/1.1";//字符串s由“GET”、“/index.html”和“HTTP/1.1”组成,中间有一个或多个空格
  String tt[] = s.split("\\s{1,}");//按照空格分割字符串,多个空格作为一个空格对字符串进行分割
  for(String str: tt)//增强的for循环
  System.out.println(str);//输出:GET
                                     //  /index.html
                                    //  HTTP/1.1          
  String qq = s.replaceAll(" {2,}", " ");//把字符串s中的多个空格替换为一个空格
  System.out.println(qq);//输出:GET /index.html HTTP/1.1 
  System.out.println(s);//输出:GET             /index.html HTTP/1.1
 }
}

阅读(1450) | 评论(0) | 转发(0) |
0

上一篇:优质代码的十诫

下一篇:我的学习经历

给主人留下些什么吧!~~