Read File line by line and search string

DKZ

Member
Joined
Aug 29, 2010
Messages
10
Programming Experience
1-3
Hi.

I like search a file TXT with this contains:

Name "Paul"
Age "11"
City "Chicago"

my question is:

Its possible get a string "Name" and give me the value "Paul"?

I have this function for get strings:

rivate Function ProcessString(ByVal strIn As String) As String
Dim astrWords As String() = New String() {"Name", "Age", "City"}
Dim strOut As String = strIn
Dim strWord As String
For Each strWord In astrWords
If strIn.IndexOf(strWord, 0) >= 0 Then
strOut = strWord
Exit For
End If
Next
Return strOut
End Function

But i can't get the values after string..

Anyone can help me?
 
for example:
VB.NET:
Function GetValue(ByVal key As String) As String
    key &= " "
    For Each line In IO.File.ReadAllLines("data.txt")
        If line.StartsWith(key) Then
            Return line.Substring(key.Length)
        End If
    Next
    Return String.Empty
End Function
 
Back
Top