hi all
i have 2 question plz help me
question 1:
how i can return the lenght of characters in a line?
my string is multi line but i want know how many char is in any line
for example in this text:
Line 1-"This is test"
Line 2-"This is"
in line 1 i have 12 character and in line 2 i have 7 character
is there any way to calculate and return this numbers?
question 2:
i want return the width of any line of a multiline
i know this possible with canvas.measurestringwidth
but when we have for example 3 word in 3 line(with CRLF)
how we can know what is the width of line 2?
and may be need to understand how many line we have
Mmmmmh... I don't think it's easy (but I'm a newbie with b4a so maybe the solution is something I don't know).
I too would like to know if there is a simple way to count the lines in word wrapped label.
Anyway, I suppose you need this information just to adapt the font size in relation with the label's size, just to have a better visualization on different display.
In this case you can use some libraries. See the following links:
you can use regex.split to split the text into lines based on the linefeed.
then you can loop throught the array and use variable length.
B4X:
Dim t As String
Dim lines() As String
t="This is test" & Chr(13) & Chr(10) & "This is"
lines=Regex.Split(Chr(13)&Chr(10),t)
For x=0 To lines.Length-1
Log(lines(x)&" : "&lines(x).Length)
Next
output:
** Activity (main) Create, isFirst = true **
This is test : 12
This is : 7
** Activity (main) Resume **