0

I have a text file which contains about 60 lines. I would like to parse out all the text from that file and display in a window. The text file contains words that are separated by an underscore. I would like to use regular expression to solve this problem.

Update:

This is my code as of now. I am trying to read "filename" in my code.

Dim filename = "D:\databases.txt"
Dim regexpression As String = "/^[^_]*_([^_]*)\w/"

I know I don't have much done here anyway but I am trying to learn VB on my own and have gotten stuck here.

Please feel free to suggest what I should be doing instead.

Victor Zakharov
  • 25,801
  • 18
  • 85
  • 151
presarioruby
  • 304
  • 4
  • 11
  • 1
    **How** would you like to solve the problem with underscores? Replace with spaces? – Victor Zakharov Apr 10 '14 at 15:05
  • Text between underscores should be shown without underscores after the button click. I would like reiterate that onButtonClick, code should go to the specified path "D:\xyz.txt", read all the data and resulting output should be without any special characters. – presarioruby Apr 10 '14 at 15:12
  • It would be a good idea if you paste what you have already done. That way we can help you out instead of doing the work for you. – the_lotus Apr 10 '14 at 15:19
  • Regarding your update, you can use the regex, but I would do it the old school way - easier to maintain and you have more control this way (see my answer). – Victor Zakharov Apr 10 '14 at 15:23

1 Answers1

0

Something like this:

TextBox1.Lines = IO.File.ReadAllLines("fileName")

To remove underscores:

TextBox1.Lines = IO.File.ReadAllLines("fileName").Replace("_", String.Empty)

If you also need other special characters removed, you can use Regex.Replace:

Also on MSDN:

Or the old school way - loop through all characters, and filter only those you need:

Community
  • 1
  • 1
Victor Zakharov
  • 25,801
  • 18
  • 85
  • 151