Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 273
  • Last Modified:

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
0
AlexPonnath
Asked:
AlexPonnath
  • 2
1 Solution
 
plusone3055Commented:
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

0
 
it_saigeDeveloperCommented:
Here is one way:
Public Class Form1
	Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		For i = 0 To Val(TextBox1.Lines.Count) - 1
			If i <> TextBox1.Lines.Count - 1 Then
				TextBox2.AppendText(String.Format("{0} - {1}{2}", TextBox1.Lines(i), TextBox1.Lines(i + 1), Environment.NewLine))
			Else
				TextBox2.AppendText(String.Format("{0} - END", TextBox1.Lines(i)))
			End If
		Next
	End Sub
End Class

Open in new window


Produces the following output:Capture.JPG
-saige-
0
 
it_saigeDeveloperCommented:
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:Capture.JPG
-saige-
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now