Android Question Split Stattement

vbmundo

Well-Known Member
Licensed User
Hi,
How can I use a SPLIT function into B4X ?

Look

Dim a() As String, s As String
Dim i As Integer
s = "1,2,33,4,5"
a = Split(s, ",")
For i = 0 To UBound(a)
Me.Print a(i)
Next i


Is a stattement to parser data

Regards

Pablo
 

lemonisdead

Well-Known Member
Licensed User
Longtime User
Hello,
You will find the Split in Margret's StringFunctions library. You'll download it here.

B4X:
Dim S As String
S = "1,2,33,4,5"
Dim myList As List = SplitMe(S,",")
Dim curPos As Int
Do While curPos < myList.Size
 Log(myList.Get(curPos))
 curPos=curPos+1
Loop



Sub SplitMe(S As String,Delimiter As String) As List
 Dim SF As StringFunctions
 SF.Initialize
 Return SF.Split(S,Delimiter)
End Sub
 
Upvote 0

vbmundo

Well-Known Member
Licensed User
This function doesn't work.

Don't return words.. only characters..

Look, this is my code

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
   
    Dim TextoEncriptado As String, Texto As String, valores As List 
   
    SF.Initialize
   
    Telefono.SetScreenOrientation(1)
    Activity.LoadLayout("Principal")
    Activity.Title="Super MySQL"
    If File.Exists(Carpeta,"reg5.smql")=True Then
       TextoEncriptado=File.ReadString(Carpeta,Archivo)
       Texto=Decrypt(TextoEncriptado)
       valores=SplitMe(Texto,"|")
       txtServidor.Text=valores.Get(0)
       txtPort.Text=valores.Get(1)
       txtUser.Text=valores.Get(2)
       txtPassword.Text=valores.Get(3)
    End If
End Sub

Sub SplitMe(S As String,Delimiter As String) As List
Dim SF As StringFunctions
SF.Initialize
Return SF.Split(S,Delimiter)
End Sub

But valores.get(0) or valores.get(1) only return a simply Character.
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
It is really not necessary to use Margret's library. You can simply use the RegEx function tout simplement:
B4X:
Dim s As String ="1,2,33,4,5"
Dim a() As String =Regex.Split(",",s)
For i = 0 To a.Length -1
    Log(a(i))  'prints 1 then 2 then 33 then 4 then 5
Next
 
Upvote 0
Top