-
January 31st, 2012, 02:16 PM
#1
text formatting
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"
To:
"2011-07-25,16:43:43,1,persons name"
or:
VarDate VarTime VarID VarName
-
January 31st, 2012, 04:30 PM
#2
Re: text formatting
You'll have to be a bit more clear the from csv is not csv the to is.
If this is to be a function that has those variables and needs to write them as a csv then that is very simple.
Code:
OutputString=Var1 & "," & Var2 & "," .........
If that is not what you are asking then please give more info.
Always use [code][/code] tags when posting code.
-
February 1st, 2012, 07:58 AM
#3
Re: text formatting
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 08:01 AM.
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
|