iOS Question Explode a string into an array

rfresh

Well-Known Member
Licensed User
Longtime User
Is there a function to explode a string into an array?

If I have a string like this: "This is a test"

Can I explode it into an array where each element of the array contains each character?

Thank you...
 

tuhatinhvn

Active Member
Licensed User
Longtime User
did you try with list?

B4X:
Dim chuoi As String
    chuoi="This is a test"
    Dim mang As List
    mang.Initialize
    For i=0 To chuoi.Length-1
        mang.Add(chuoi.SubString2(i,i+1))
    Next
Log(mang)
 
Upvote 0

rfresh

Well-Known Member
Licensed User
Longtime User
How do I access an element in the list?

mang(0) or mang[0] isn't correct?
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
mang.Get(0)

You could also use an Array of Strings:
B4X:
Dim chuoi As String
chuoi = "This is a test"
Dim mang(chuoi.Length) As String
For i = 0 To chuoi.Length - 1
    mang(i) = chuoi.SubString2(i, i + 1))
Next

and then use mang(index) to access each value
 
Last edited:
Upvote 0
Top