iOS Question How can I split a string for a pattern?

davepamn

Active Member
Licensed User
Longtime User
where can I find b4i regular expressions?

Here is what I want to do
B4X:
    Dim arrElements() As String
    arrElements=sTestIdValue.split("<ListItem>")
 

davepamn

Active Member
Licensed User
Longtime User
B4X:
<ListItem>Red</ListItem>
<ListItem>Green</ListItem>
<ListItem>Blue</ListItem>
Sub RemoveTag(sBeginTag As String, sEndTag As String,sPhrase As String) As String
    Dim sRetVal As String=""
    sRetVal=Regex.Replace(sBeginTag,sPhrase,"")
    sRetVal=Regex.Replace(sEndTag,sRetVal,"")
    Return (sRetVal)
End Sub
    Dim oLBX As Picker

            oLBX.Initialize("lbx" & i)
            Dim myList As List
            myList.Initialize
       

            Dim sPattern As String
            Dim Matcher1 As Matcher
            Dim sBuffer as string

            sPattern="\<ListItem\>(.*?)\<\/ListItem\>"

            Matcher1=Regex.Matcher2(sPattern,Regex.MULTILINE,sTestIdValue)
            Do While Matcher1.Find
               sBuffer=RemoveTag("<ListItem>","</ListItem>",ListMatcher1.match)
                myList.Add(sBuffer)
            Loop

            oLBX.SetItems(0,myList)

This worked
 
Last edited:
Upvote 0
Top