get value in textArea Individually line

hi
If I want to get value in a textArea Control Individually line how to?

You can use nthfield(textarea.text, ChrB(&h0D), ) to get a single line from the textarea. Countfields(textarea.text, ChrB(&h0D)) will give you the number of lines. NB nthfield starts at line 1.

Alternatively you could split the textarea.text into a table:

Dim s() As String = Split(textarea.text, ChrB(&h0D))

Okay thank

What is “ChrB(&h0D)” To do anything?

if I want count num of string Individually line How to ?

It is not so smart to use ChrB here, Wayne, because that will return strings without encoding, causing trouble with any chars that are not plain ASCII. It’s totally safe, however, to use Chr() for these codes.

Also, depending on the platform, the lines may not be separated by CRs. It’s safer to use the EndOfLine constant here. To be extra safe, also use the ReplaceLineEndings function, see below.

I suggest using the Split function over the NthField-Functions because it’s much faster once you get to have more than a few lines.

So, first split the text into separate lines, like this:

dim lines() as String = ReplaceLineEndings(textarea.Text,EndOfLine).Split(EndOfLine)

dim lineCount as Integer = lines.UBound+1

to go over all lines:

for i as integer = 0 to lines.Ubound dim line as String = lines(i) ... now you can use the "line" next i

for excample.
I key string value in textArea1 3 line for excam
“sasdaaadaaa
sdfgdgggdgdg
grtertwrwrwwr”

I write code

dim lines() as String = ReplaceLineEndings(TextArea1.Text,EndOfLine).Split(EndOfLine)
dim lineCount as Integer = lines.UBound+1

for i as integer = 0 to lines.Ubound
dim line as String = lines(i)
MsgBox lines(i)
next i

then I run program then Have message “sasdaaadaaasdfgdgggdgdggrtertwrwrwwr”
but I want
lines(1) = “sasdaaadaaa”
lines(2) = “sdfgdgggdgdg”
lines(3) = “grtertwrwrwwr”

Sorry Thomas Tempelmann.
I’m doing success
Thank you !

[quote=31487:@wittawat suwannarak]but I want
lines(1) = “sasdaaadaaa”
lines(2) = “sdfgdgggdgdg”
lines(3) = “grtertwrwrwwr”[/quote]
Note that array in Xojo always count starting with 0 to N-1, not from 1 to N!
So, it’s lines(0) to lines(2).

Glad to see you got it working.

Then if I have Variable two Variable for excample

dim strA as string
dim strB as string
strA = “ffffffff”
strB = “mmmmmm”

Then I want get “strA” to place in TextArea1 where number of line in textArea1 is One
And I want get “strB” to place in TextArea1 where number of line in textArea1 is two

How to ?

Do you want to let the user edit the text? If not, then I suggest you use a Listbox instead of a TextArea. In a Listbox, it is much easier to add and remove lines (named “rows” in a listbox).

If you want to stay with a TextArea, try this:

[code]// first, get the text into an array of lines:
dim lines() as String = ReplaceLineEndings(TextArea1.Text,EndOfLine).Split(EndOfLine)

// then make sure that there are at least 2 lines in the array so that they can be assigned (otherwise, one gets an outofBounds exception)
if lines.Ubount < 1 then
redim lines(1) // this gives us two lines (at index 0 and 1)
end

// now replace the lines
lines(0) = strA
lines(1) = strA

// and store it back in the textarea:
TextArea1.Text = Join (lines, EndOfLine)[/code]