how to parse a CSV file

Discuss RoboTask here
Post Reply
mhamlett101
Posts: 3
Joined: Wed Oct 19, 2022 4:52 pm

how to parse a CSV file

Post by mhamlett101 »

what i have is a csv file
example data
2222,aaa,123.45,fffff
33,bb,45.00,gggg

how do i extract the 123.45 and 45.00 on each line?

thanks
Oleg
Site Admin
Posts: 3135
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: how to parse a CSV file

Post by Oleg »

Look at my example below. Save the text of the task to a file and use menu Task->Import to import the task into RoboTask.
Also you can simply copy task text and paste it into the task list.
You can get an element of standard comma-separated string by specifying its index number starting from 0. For example {MyVar(2)}
Read more about variables here

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|1459598804
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DisableOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task54"
Hide=INTEGER|0
ID=INTEGER|833845300
LogOnAsUser=INTEGER|1
Name=STRING|"Parse CSV text"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER

[Actions\Action1]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""MyText"" with value ""234,aaaa,00000676,123.45, abcd"""
Params=FOLDER

[Actions\Action1\Params]
expand=STRING|"0"
linecount=STRING|"2"
varname=STRING|"MyText"
varvalue=STRING|"234,aaaa,00000676,123.45, abcd"
varvalue00000001=STRING|"111,bb,00000676,23.00, abcde"

[Actions\Action2]
ActionID=STRING|"A_LOOP_TEXT"
Enabled=INTEGER|-1
Name=STRING|"Text Loop"
Params=FOLDER

[Actions\Action2\Params]
destvar=STRING|"LINE"
line0=STRING|"{MyText}"
linecount=STRING|"1"
sourcetext=STRING|"1"

[Actions\Action3]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""Full line: """
Params=FOLDER

[Actions\Action3\Params]
icon=STRING|"1"
msg0=STRING|"Full line: "
msg1=STRING|"{Line}"
msg3=STRING|"Price: {Line(3)}"
msgcount=STRING|"4"
playsound=STRING|"0"
showmessage=STRING|"1"

[Actions\Action4]
ActionID=STRING|"A_LOOP_END"
Enabled=INTEGER|-1
Name=STRING|"End Loop"

Oleg Yershov
Post Reply