Android Question Regex B4A & B4J

OliverA

Expert
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: https://stackoverflow.com/q/38513563 (see the comments)

 
Upvote 1

Mahares

Expert
Licensed User
Longtime User
B4A: 5 strings - "" "1" "2" "3" "4"
You never quit Mario. I quickly tested and it shows 4 elements in B4A
B4X:
Dim components() As String
    components = Regex.Split("", "1234")
    Log(components.Length)
    For i =0 To components.Length-1
        Log(components(i))
    Next
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
1701694405500.png
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
I tested it too and I got 4 elements.
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
Where Regex come from?
Is it included in Java JDK?
Could it be something related to the Java version?
@LucaMs which version of Java do you have in your path?
I tested with Open JDK 14 and 17.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
@lucas, can you upload the project that produces this issue?
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
It has nothing to do with the JDK you're using, but Android's implementation of (java.util.regex.Pattern) (if it is an actual problem). Are you doing this on a real device? What Android version?

Links:
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
I am speechless
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
This may be related to this issue:

 
Upvote 0

Similar Threads

Top