I wish I could select a line from a string.
The user is invited to fill out a textarea.
After I would like to split this textarea by line.
Actually, this is my sub.
It works, but if the user does not put text in the first lines, my sub will return the first line with text as the first line.
The user is invited to fill out a textarea.
After I would like to split this textarea by line.
B4X:
Sub ExtraireLigne(nligne As Int,text As String) As String
Dim aPos,bPos As Int=0
Dim t As String
Dim c As Byte = 26
text=text.Trim
For n=0 To nligne-1
Try
bPos=text.IndexOf2(Chr(10),aPos)
Catch
End Try'ignore
Try
If bPos = -1 Then
bPos=text.Length
End If
If bPos-aPos>26 Then
Do While text.CharAt(aPos+c)<>" "
c=c-1
Loop
bPos=aPos+c
End If
If aPos>text.Length Then
t=""
Return t
End If
t=text.SubString2(aPos,bPos)
Catch
t=""
End Try
aPos=bPos+1
Next
Return t
End Sub
Actually, this is my sub.
It works, but if the user does not put text in the first lines, my sub will return the first line with text as the first line.