Valeria Kaya
Valeria Kaya

Reputation: 131

VB.NET unwanted extra break

I have the code below;

Dim orderlist As List(Of String) = New List(Of String)
For i As Integer = 0 To newacctlist.Items.Count - 1
    orderlist.Add("This order will be placed on" & newacctlist.Items(i))
Next (i)
Textbox1.Lines = orderlist.ToArray

When I import items from txt file, as result, 1st i comes out correct, but the next ones get an unwanted break. They come out as:

This order will be placed on
Monday

instead of

This order will be placed on Monday

Import from txt file

Dim a As String = My.Computer.FileSystem.ReadAllText(path & "\neworder.txt")
Dim b As String() = a.Split(vbNewLine)
newacctlist.Items.AddRange(b)

How can I fix this error?

Thanks in advance

Upvotes: 0

Views: 68

Answers (2)

Koen
Koen

Reputation: 2571

The only thing I can think of is that you have a newline-character in your newacctlist-items.

Put a breakpoint on the orederlist.Add() line and check those values.

Also take a look at the code where you create the newacctlist. Probably your culprit is there.

** Edit **

Your split on vbNewLine includes it in the string.

Dim a As String = My.Computer.FileSystem.ReadAllText(path & "\neworder.txt")
Dim b As String() = a.Split(vbNewLine)
For Each s As String In b
    Console.WriteLine(s.Replace(vbCr, "").Replace(vbLf, ""))
Next

Upvotes: 1

inquisitive
inquisitive

Reputation: 3629

trim it,

orderlist.Add("This order will be placed on" & newacctlist.Items(i).Trim  )
---------------------------------------------------------------------^

Upvotes: 3

Related Questions