Link to home
Start Free TrialLog in
Avatar of AlexPonnath
AlexPonnathFlag for United States of America

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
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

Open in new window


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
Avatar of plusone3055
plusone3055
Flag of United States of America image

For i = 0 To Val(TextBox1.Lines.Count) - 1
  if  val = "NC" Then 
 val = "NC - NCI" 
ELSE IF  val = NCI THEN 
val =  NCI - TLV
ELSE IF  (you get the idea :) ) 
next

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of it_saige
it_saige
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
And just to show another method, this one uses LINQ:
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

Open in new window


Produces the following results:User generated image
-saige-