user1952907
user1952907

Reputation: 11

How to print a long string into a table separated by #

I have a long string of three words at the end of each one there # Is all stored in a text file How to print it until the # in the file: Jorj# bush# 123456# the president of USA# i want sonthing like:

Dim details() As String = IO.File.ReadAllLines(filename)
Dim query = From line In details
            Let fullname = line.Split("#"C)(0)
            Let family_name = line.Split("#"c)(1)
            Let phone_number = line.Split("#"c)(2)
            Let comment = line.Split("#"c)(3)   
            Select fullname, family_name, phone_number, comment

Upvotes: 0

Views: 60

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460268

That should work as expected. But you could make it more efficient:

Dim query = From line In details
            Let parts = line.Split("#"c)
            Let fullname = parts(0)
            Let family_name = parts(1)
            Let phone_number = parts(2)
            Let comment = parts(3)
            Select fullname, family_name, phone_number, comment

Otherwise you're splitting every line 4 times.

Upvotes: 2

Related Questions