Android Question Regex B4A & B4J


Licensed User
Longtime User
Solved so:
    Dim components() As String
'   components = Regex.Split("", "1234")
    components = Regex.Split("(?<=.)", "1234")
    Log("Length: " & components.Length)
    For i = 0 To components.Length - 1
        Log("Component " & components(i))
But who solved it that way? ChatGPT 😄
Upvote 0


Licensed User
Longtime User
Yes, same code, different behaviors.
It depends on the android version.
on a device ( all real device ) with:
Android 8 I have the 5 values (wrong)
Android 11 is fixed
Android 13 is fixed
Upvote 0


Licensed User
Longtime User
Found the answer on stackoverflow. The behavior when dealing with an empty String pattern has changed between Java 7 and Java 8. Depending on the version of Android, you may be dealing with Java 6, 7 or 8. This has nothing to do with the with the JDK you use in B4A to generate you APK, but with the Java implemented within Android.

This is the expected behavior for String#split for Java version up to 7 and has been changed in Java 8: Why in Java 8 split sometimes removes empty strings at start of result array?
– Tom
Jul 21, 2016 at 20:44
Source: (see the comments)

Upvote 1

Similar Threads