i am trying to edit a csv file from:
Return(result="success" dev_id="0" time="2011-07-25 16:43:43" id="1" name="persons name" workcode="" status="1" card_src="from_check"
If you want to extract the actual data from a line like given you'd need a little parser to find the keywords like "result" and then extract the data which comes always in quotes.
Code:
Private Function Parse(ByVal Line As String, ByVal KeyWord As String) As String
Dim p%, p1%, p2%
p = InStr(Line, KeyWord + "=") 'find the keyword
If p Then 'if the keyword plus "=" exists
p1 = p + Len(KeyWord) + 2 'find starting position of data
p2 = InStr(p1, Line, """") 'find ending position of data
Parse = Mid$(Line, p1, p2 - p1) 'extract data
End If
End Function
Private Sub Command1_Click()
Dim MyLine$
MyLine = "Return(result=""success"" dev_id=""0"" time=""2011-07-25 16:43:43"" id=""1"" name=""persons name"" workcode="""" status=""1"" card_src=""from_check"""
Print Parse(MyLine, "result")
Print Parse(MyLine, "dev_id")
Print Parse(MyLine, "time")
End Sub
Note, that I had to double all the quotes to put them into a variable. You would presumably read one line like that and have it already imn a variable.
You call the Parse function for each keyword which then returns the data without anymore quotes.
Instead of Print the data you would possibly put them in variables like VarResult = Parse(MyLine, "result")
Last edited by WoF; February 1st, 2012 at 07:01 AM.
Bookmarks