AlexPonnath
asked on
Building a custom string based on data read from MultiLine Text Box
I was wondering what the best way is to do the following. I have a multiline textbox which I place text inand
then via function read line by like. The data in text box looks like this
now what I like to do is read each line by line which I do via
Which works all fine but now comes the part I am unsure off, I need to create an output in a second textbox which has a syntax like this
So its the first item - 2nd Item, then 2nd Item - 3rd Item and so on as far as the logic goes
then via function read line by like. The data in text box looks like this
NC
NCI
TLV
TTT
QACI
now what I like to do is read each line by line which I do via
For i = 0 To Val(TextBox1.Lines.Count) - 1
next
Which works all fine but now comes the part I am unsure off, I need to create an output in a second textbox which has a syntax like this
NC - NCI
NCI - TLV
TLV - TTT
TTT - QACI
QACI - END (End because its the last item in List and no more values)
So its the first item - 2nd Item, then 2nd Item - 3rd Item and so on as far as the logic goes
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
And just to show another method, this one uses LINQ:
Produces the following results:
-saige-
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For Each value In (From item In TextBox1.Lines _
Select String.Format("{0} - {1}", item, _
(If(Array.IndexOf(TextBox1.Lines, item) <> (TextBox1.Lines.Count() - 1), _
String.Format("{0}{1}", TextBox1.Lines(Array.IndexOf(TextBox1.Lines, item) + 1), Environment.NewLine), _
"END"))))
TextBox2.AppendText(value)
Next
End Sub
End Class
Produces the following results:
-saige-
Open in new window