码迷,mamicode.com
首页 > 编程语言 > 详细

java 截取字符串

时间:2015-08-16 19:35:25      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:

使用split:按规定分割,并存放到数组中

public class TestDemo {

@Test
public void test() {
String s = new String("01:大汽车"); 
String a[] = s.split(":"); 

System.out.println(a[0]); 
System.out.println(a[1]); 
}

}

使用 substring: substring(int beginIndex) 返回一个新的字符串,它是此字符串的一个子字符串,为beginIndex之后的字符串

                         substring(int beginIndex, int endIndex) 返回一个新字符串,它是此字符串的一个子字符串,为索引在beginIndex到endIndex之间的字符串

                         

@Test
    public void test01(){
        String msg="aaaahiljljlihgiuywwwwwww";
        String re = msg.substring(8);
        String res=msg.substring(8,9);
        System.out.println(res);
        System.out.println(re);
        
    }

 

java 截取字符串

标签:

原文地址:http://www.cnblogs.com/liangjiehai/p/4734705.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!