Click here to Skip to main content
15,849,571 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi guys,
i have a multiline textbox in my visualbasic project like this:

and i want to add a dash to beginig of all lines execpt the first line like this:
- line2
- line3
- line4

with loop like ``` for each line in textbox1.lines``` add dash to all lines, but i want to add dash to all lines except line one.

What I have tried:

I have no idea how to do this
Updated 20-Jan-23 14:37pm

Don't use foreach for this. Use a normal for loop and start the index at 1 instead of 0.

The TextBox does not know the concept of "line" so you have to parse the text, probably .Split on Environment.NewLine, the go through the resulting string array and just not modify the first item in the array.
Share this answer
Member 12617947 21-Jan-23 1:58am    
Thank you, dear friend. That is exactly what I wanted.
This is a pretty straightforward task:
Dim text = "Line 1" + vbCrLf +
           "Line 2" + vbCrLf +
           "Line 3" + vbCrLf +
           "Line 4" + vbCrLf +
           "Line 5" + vbCrLf

Dim lines = text.Split(New Char() {vbCr, vbLf}, StringSplitOptions.RemoveEmptyEntries)

text = String.Join(vbCrLf + "- ", lines) + vbCrLf
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900