Android Question String Array in SQLite

tdocs2

Well-Known Member
Licensed User
Longtime User
Greetings, all.

Thank you in advance for answering my question.

I have a string array consisting of single characters:

B4X:
Dim ArrayExample(26) as string

I want to make the array part of a table in SQLite.

How do I save a String Array in SQLite?

Can I just code ArrayExample as TEXT?
or
Do I have to first convert the string array, ArrayExample, to a string using StringBuilder?

Best regards.

Sandy
 

tdocs2

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

tdocs2

Well-Known Member
Licensed User
Longtime User
You could use the library ByteConverter and its functions StringFromBytes - StringToBytes.

(But... do you need to save all 26 letters in a field in every record?)

Ciao, Luca, and thank you for your generous support.

The 26 letters are 26 choices related to each record. What is wrong with:

B4X:
Sub ArraytoString
Dim ArrayExample(26) As String
Dim sb As StringBuilder
Dim result As String
For i=0 To 25
    ArrayExample(i)=Chr(65+i)
Next
sb.Initialize
For j=0 To 25
    sb.Append(ArrayExample(j))
Next
result=sb.ToString
Log ("Result " & result)
End Sub

The log shows:

B4X:
Result ABCDEFGHIJKLMNOPQRSTUVWXYZ

Maybe not elegant but it seems to work.

Best regards.

Sandy
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…