In string, the Split method is as follows:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6E/57/wKiom1V5V4vB-UifAABPIVl1KsA500.jpg "style=" float: none; "title=" String0.png "alt=" Wkiom1v5v4vb-uifaabpivl1ksa500.jpg "/>
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6E/53/wKioL1V5WTKw1LVgAABipXk0ufk248.jpg "style=" float: none; "title=" String1.png "alt=" Wkiol1v5wtkw1lvgaabipxk0ufk248.jpg "/> Visible, the core of Split is Pattern.compile (regex). Split (this, limit);
Java provides pattern,matcher to support the regular, you can see an example:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/6E/57/wKiom1V5WHjQ18udAAEmAHAt7yY052.jpg "title=" String3.png "alt=" Wkiom1v5whjq18udaaemahat7yy052.jpg "/>
The operating result is: 0,1 || 3,4 |ab| 7,8 |cef| 8,9 || 11,12 |kk| 13,14 |a|
It is important to note that:
Given a pattern (regex) by pattern, Matcher can constantly (find) match text and find every a horse match the beginning of the content (start), end index "End index" that's start+ . The length of the text.
Subsequence (Begin,end) is a "Baotou Non-trailer" method
Problem: In the upper while, the largest index we can reach is the last end, and it's possible to notice this After the end there is content, then how to deal with it? If a regular has split the text into parts, do we just need a part? If there is an empty string in the divided section, how does split work?
We can take these questions to look at the source code:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/6E/54/wKioL1V5XurQ1CqfAAJMp4wDURg874.jpg "title=" String4.png "alt=" Wkiol1v5xurq1cqfaajmp4wdurg874.jpg "/>
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/6E/54/wKioL1V5Yt3QNxZ5AAIHWzkZ2QE768.jpg "title=" String5.png "alt=" Wkiol1v5yt3qnxz5aaihwzkz2qe768.jpg "/>
First, the effect of limit on matchlimited:
The limit < 0 or split (regex) is equivalent to split (regex,0) ==> Matchlimited:false Limit > 0 ==> matchlimited:true
In fact, while means that if limit>0, matchlist only add a limited amount of content. If the entire text does not match, it returns an array of length 1, with its own contents. If limit is 0, then the last matching empty string is deleted until the string is returned.
|