Android Question [Solved] How to read line by line a text with several lines?

Sergio Castellari

Active Member
Licensed User
Situation:
Read a "Text" type field from a MySQL Database that can contain several lines or even none. (currently the field can be obtained by jRDC2)

Needed:
a) Read how many lines of up to 100 characters it contains.
b) If you have 1 or more lines, read one by one through a loop to later be added to a B4XTable

Greetings
 

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
You can use the Regex.Split function to split your text on CR (or CRLF depending on the system the text is coming from).

This will give you an array of strings, the array .Size value will be how many lines of text there is.
 
Upvote 2

Sergio Castellari

Active Member
Licensed User
Thank you very much sir @Jeffrey Cameron !!!
With your reference I achieved my goal.

B4X:
                    'Leo la Descripcion detallada renglon por renglon           
                    Dim lineas() As String                                                                'Inicializo un Array
                    lineas = Regex.Split(Chr(13),cDes)                                        'Separo cada linea x Chr(13) final
                    If lineas(0).ToLowerCase <> "Null".ToLowerCase Then        'Verifico si existe al menos un renglon con texto
                        For i=0 To lineas.Length -1                                                    'Leo cada renglon seaprado del array
                            Dim cLin As String                                                               
                            cLin = lineas(i).Trim                                                            'Quito espacios adelante/atras
                            If cLin.Length > 0 Then                                                        'Si tiene por lo menos una letra, la muestro
                              aCampos2.Initialize
                                aCampos2.Add("")
                                aCampos2.Add("")
                                aCampos2.Add(cLin)
                                aCampos2.Add("")
                                aCampos2.Add("D")
                                aRegistros.Add(aCampos2)
                            End If
                        Next
                    End If
[/CÓDIGO]

[B]A million thanks![/B]
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…