Bug? regex single char split

sorex

Expert
Licensed User
Longtime User
I don't know if this is a bug in a library or default behaviour in Java
but this seems suspicious and it's not the output I got in several other languages.


B4X:
Log ( hours )
Log ("!" & DateTime.GetHour(DateTime.Now) &"!")
Log ( "0:" & Regex.Split("",DateTime.GetHour(DateTime.Now))(0) )
Log ( "1:" & Regex.Split("",DateTime.GetHour(DateTime.Now))(1) )
Log ( "2:" & Regex.Split("",DateTime.GetHour(DateTime.Now))(2) )
Log ( "C:" & Regex.Split("",DateTime.GetHour(DateTime.Now)).Length)


the output is:

19
!19!
0: <- should be 1
1:1 <- should be 9
2:9 <- should not exist
C:3 <- should be 2

the value in the array at position 0 should not even exist since there is no leading space (the !19! proves this)
 

sorex

Expert
Licensed User
Longtime User
that will make an array of each individual charater, so it's easy to find/fetch the right char.

I know you can do the same with substr but I use(d) split/explode a lot so it's kind of a habbit to stick to it :)

I'll keep in mind that the empty split starts at 1 instead of the traditional 0 in the array
(works fine (pos 0 in the array) with the none empty split, just tested this)
 

sorex

Expert
Licensed User
Longtime User
that's my point, why use a loop when 1 command does the same?

(Ok internally it probably uses the same trick anyway)
 
Top