Reading TextBox info line by line

K

kimiraikkonen

I can import a .txt document into a TextBox

Each line in the TextBox contains a URL, for example,http://www.whateverdomain.com

I would like to convert each URL to the following format:
<a href="http://www.whateverdomain.com">http://www.whateverdomain.com</a>

Obviously I'm a dumb noob. I know how to convert a single line of text but can't figure out how to treat line-by-line, multiple entries in a TextBox..

Thanks in advance for your suggestions.

Hi Gregory,
Textbox control has Lines() property which returns all the lines
located in textbox. So, you can convert all the lines (lines, which
represent URLs) using with another array(myurlarr) as follows:

' Assuming you have pure URLs line by line in TextBox1
' The core of the job
Dim myurlarr() As String
myurlarr = TextBox1.Lines
For x As Integer = 0 To myurlarr.Length - 1
myurlarr(x) = "<a href=" & """" & TextBox1.Lines(x) & _
"""" & ">" & TextBox1.Lines(x) & "</a>"
Next


' Optionally, you may want to see converted output
For x As Integer = 0 To myurlarr.Length - 1
MsgBox(myurlarr(x).ToString)
Next

I tested the code that i wrote and i hope it'll work for you,


Onur Güzel
 
J

James Hahn

For Each S As String In Split(TextBox1.Text, vbCrLf)
<process S>
Next

I can import a .txt document into a TextBox

Each line in the TextBox contains a URL, for example,
http://www.whateverdomain.com

I would like to convert each URL to the following format:
<a href="http://www.whateverdomain.com">http://www.whateverdomain.com</a>

Obviously I'm a dumb noob. I know how to convert a single line of text but
can't figure out how to treat line-by-line, multiple entries in a TextBox.

Thanks in advance for your suggestions.
 
G

Gregory Leck

Thanks for that. It works great. I guess I need to learn more about arrays before I get too ambitious!

***
I can import a .txt document into a TextBox

Each line in the TextBox contains a URL, for example, http://www.whateverdomain.com

I would like to convert each URL to the following format:
<a href="http://www.whateverdomain.com">http://www.whateverdomain.com</a>

Obviously I'm a dumb noob. I know how to convert a single line of text but can't figure out how to treat line-by-line, multiple entries in a TextBox.

Thanks in advance for your suggestions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top