Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello,
how can i read the same line from a file into two textboxes.
line1:
First name     12.04.1996
I want to read the first name in textbox1 and the date in textbox2
I used this way to read the line:

What I have tried:

VB
Dim strm As System.IO.StreamReader = New System.IO.StreamReader(file)
Dim line1 As String
line1 = strm.ReadLine()
text1.Text = line1
Posted
Updated 4-Jun-19 22:34pm
v2

1 solution

If you want to extract the two pieces of information from the string, use the Split[^] method on the string:
VB.NET
Dim parts As String() = line1.Split("     ")
Dim firstName As String = parts(0)
Dim dateStr As String = parts(1)
text1.Text = firstName
text2.Text = dateStr
 
Share this answer
 
Comments
Member 14480131 5-Jun-19 4:59am    
thank you, i have in line1 info like this:
1.first name(John kely) 12.04.1996
and when i use split(" "), i am getting 1 in text1 and first in text2
Thomas Daniels 5-Jun-19 5:04am    
I based my code on the exact string in your question -- if your real data looks different, then you might need a different argument to the Split method or you may need to take other elements than the first and the second, or you may need to split twice.
Member 14480131 5-Jun-19 5:10am    
how can i take the last 10 argument to show it in text2 ? and delete it from text1
Thomas Daniels 5-Jun-19 5:10am    
I don't know what "last 10 argument" means.
Member 14480131 5-Jun-19 5:15am    
i have always the date at the end of the line

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