-
Nov 21st, 2017, 06:52 AM
#1
Thread Starter
Member
read some line in txt file
hi to All
want in a txt file, Print a certain amount of line in richbox
For example, the contents of a txt file are as follows:
Code:
ro.build.date.utc=1499401014
ro.build.type=user
ro.build.user=dpi
ro.build.host=SWHE8822
In the first line "ro.build.date.utc=" Equals with "1499401014"
I need the syntax to read 1499401014 from a file , The value of 1499401014 varies in different files
In other words, I want to print anything in front of ro.build.date.utc= on Richbox.
How can we do it? for better understanding I need a ready command
Thanks
-
Nov 21st, 2017, 09:04 AM
#2
Re: read some line in txt file
Just to get you started. You will need to modify this to work for yourself:
Imports System.IO
Code:
Dim line As String
Using sr As StreamReader = New StreamReader("C:YourText.txt")
line = sr.ReadLine()
Do Until sr.EndOfStream
If InStr(line), "ro.build.date.utc=") > 0 Then
RichTextBox1.Text = "LOOK UP INDEX OF"
End If
line = sr.ReadLine()
Loop
End Using
Once the code finds the string look up "IndexOf" to parse the Line for the number.
Last edited by TysonLPrice; Nov 22nd, 2017 at 05:09 AM.
Please remember next time...elections matter!
-
Nov 21st, 2017, 10:40 PM
#3
Re: read some line in txt file
Like any problem, you should start by breaking it down into smaller problems. Beginners often can't find information on their problem because they look for a turnkey solution to their exact problem. If noone has written anything on that exact problem before, there's nothing to find. You need to break the problem up into parts and then preferably generalise each one and look for information on each of those. You then build up your knowledge of the general parts and put that knowledge together to solve the whole.
If you want to do something with the lines of a text file then obviously you need to be able to read the lines of a text file. That's going to be the same regardless of what you want to do, so you should learn how to do that first. It's easy to find information online on how to read the lines of a text file in VB.NET.
Once you have read the file as lines you will know that each line is stored as a String and the problem then becomes how to get part of a String if another part is equal to something else. Again, it's easy to find information on the general topics of string manipulation and pattern matching. Once you understand the principles involved, then you can apply that knowledge you your specific case. That's how you learn to code. Copying turnkey solutions to specific problems will be a slow road to being a poor programmer. Break up a problem, generalise, learn the principles, apply them and then combine. The more you do that, the more you'll find that you already know the principles and how to apply them for large chunks of your problems and eventually all of them.
-
Feb 2nd, 2018, 09:41 AM
#4
Thread Starter
Member
Re: read some line in txt file
Originally Posted by TysonLPrice
Just to get you started. You will need to modify this to work for yourself:
Imports System.IO
Code:
Dim line As String
Using sr As StreamReader = New StreamReader("C:YourText.txt")
line = sr.ReadLine()
Do Until sr.EndOfStream
If InStr(line), "ro.build.date.utc=") > 0 Then
RichTextBox1.Text = "LOOK UP INDEX OF"
End If
line = sr.ReadLine()
Loop
End Using
Once the code finds the string look up "IndexOf" to parse the Line for the number.
Errors for InStr This Command
Originally Posted by jmcilhinney
Like any problem, you should start by breaking it down into smaller problems. Beginners often can't find information on their problem because they look for a turnkey solution to their exact problem. If noone has written anything on that exact problem before, there's nothing to find. You need to break the problem up into parts and then preferably generalise each one and look for information on each of those. You then build up your knowledge of the general parts and put that knowledge together to solve the whole.
If you want to do something with the lines of a text file then obviously you need to be able to read the lines of a text file. That's going to be the same regardless of what you want to do, so you should learn how to do that first. It's easy to find information online on how to read the lines of a text file in VB.NET.
Once you have read the file as lines you will know that each line is stored as a String and the problem then becomes how to get part of a String if another part is equal to something else. Again, it's easy to find information on the general topics of string manipulation and pattern matching. Once you understand the principles involved, then you can apply that knowledge you your specific case. That's how you learn to code. Copying turnkey solutions to specific problems will be a slow road to being a poor programmer. Break up a problem, generalise, learn the principles, apply them and then combine. The more you do that, the more you'll find that you already know the principles and how to apply them for large chunks of your problems and eventually all of them.
I accept
But I do not know English well
That's why I can not understand more of your explanation
And I can get ready with the command and investigate my efficiency
There is very little training in our language
Please put a command for my problem
thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|