Java about split split string, NULL results can not get the problem, the processing of multiple delimiters

Source: Internet
Author: User
Source   http://java2000-net.iteye.com/blog/242162

First look at the source code Java code/** * * @author Zhaoqing <a href= "http://www.java2000.net" >www.java2000.net</a> * * * * clas       s T {public static void main (string args[]) {string num[] = new STRING[11];       String sline = "101494|360103660318444|2008/06/17| Zhou Runying |1292.0|3085.76|2778.28|912.91|106.0| | |";       num = Sline.split ("\\|");       int row = 1;       for (String s:num) {System.out.println (row+++ "=" +s); }     }   }

Run result is

1=101494

2=360103660318444

3=2008/06/17

4= Zhou Runying

5=1292.0

6=3085.76

7=2778.28

8=912.91

9=106.0

View API, there is a Java code public string[] Split (String regex, int limit);

The limit parameter controls the number of application modes, thus affecting the length of the resulting array.

if the limit n is greater than 0 , then the pattern applies at most n>-1 times, the length of the array is not greater than N, and the last entry of the array will contain all input except the last matching delimiter.

if n is not positive , the number of times the mode is applied is unrestricted, and the array can be of any length.

if n is zero , then the number of applied modes is unrestricted, the array can be any length, and the trailing empty string is discarded. Modify code to

Java Code/** * * @author Zhaoqing <a href= "http://www.java2000.net" >www.java2000.net</a> * * */class T {       public static void Main (string args[]) {string num[] = new STRING[11];       String sline = "101494|360103660318444|2008/06/17| Zhou Runying |1292.0|3085.76|2778.28|912.91|106.0| | |"; num = Sline.split ("\\|",-1);       Here use-1 as the parameter int row = 1;       for (String s:num) {System.out.println (row+++ "=" +s); }     }   }

Run results

1=101494

2=360103660318444

3=2008/06/17

4= Zhou Runying

5=1292.0

6=3085.76

7=2778.28

8=912.91

9=106.0

10=

11=

12=


Java string delimiter split/stringtokenizer <!> comparison Two representations use the Split function: String s = new string ("2_8_7_4_3_9_1"); String [] arr = S. Split ("_"); Using the StringTokenizer class: String s = new string ("2_8_7_4_3_9_1"); StringTokenizer Commatoker = new StringTokenizer (S, "_"); String

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.