public String[] split(String regex, int limit)
>
str1.split("b", -1).length = 7
str[0]=a
str[1]=
str[2]=c
str[3]=
str[4]=
str[5]=
str[6]=x
end
peter tong wrote:Why the function returns empty string between two consecutive single 'b'?
input string = "06265680,8800.00|00496455,5076.72|"
input.split("|", -1).length = 36
str[0]=
str[1]=0
str[2]=6
str[3]=2
str[4]=6
str[5]=5
str[6]=6
str[7]=8
str[8]=0
str[9]=,
str[10]=8
str[11]=8
str[12]=0
str[13]=0
str[14]=.
str[15]=0
str[16]=0
str[17]=|
str[18]=0
str[19]=0
str[20]=4
str[21]=9
str[22]=6
str[23]=4
str[24]=5
str[25]=5
str[26]=,
str[27]=5
str[28]=0
str[29]=7
str[30]=6
str[31]=.
str[32]=7
str[33]=2
str[34]=|
str[35]=
end
input string = ""
input.split("\|", 0).length = 1
str[0]=
end
peter tong wrote:the "|" is never occur in the empty input string, but it also return length = 1, why again?
Splits this string around matches of the given regular expression.
The array returned by this method contains each substring of this string that is terminated by another substring that matches the given expression or is terminated by the end of the string. The substrings in the array are in the order in which they occur in this string. If the expression does not match any part of the input then the resulting array has just one element, namely this string.
peter tong wrote:Why the function returns empty string between two consecutive single 'b'?
Balabo Haeron wrote:
peter tong wrote:Why the function returns empty string between two consecutive single 'b'?
you can specify the number of characters within your delimiter by either using say "b[2]" to denote a delimiting 2 consecutive strings or "b*", i.e. a b followed by any other character.
Surely it is b{2}? That does not mean two consecutive strings but two consecutive letters b.Balabo Haeron wrote: . . . "b[2]" to denote a delimiting 2 consecutive strings
Surely that means any number of letters b including 0? Not b followed by any other character.... "b*", i.e. a b followed by any other character.