Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Setting ICsv object using a temporary 2 dim Array
#1
If I have a one dimensional array and a string that get's it content changed, those 2 items must be put in a ICsv object.
What is the best (fastest/efficient) way to set (initiate) the ICsv object?

To be more clear, the beneath example:
1 dimensional array = in_extracted_sections[ ]
string that changes = extracted_section_content

Those 2, I want to put in the ICsv object v

To set the ICsv object, I use:
Macro Macro23
Code:
Copy      Help
;; The temporary array that 'sets' ICsv
ARRAY(str) tmp_arr.create(2 in_extracted_sections.len)
(I set the columns on '2' and the 'length' to the length of the 1 dim Array in_extracted_sections[ ])

Macro Macro23
Code:
Copy      Help
int i
str in_settingsfile_content
str extracted_section_content ;; The string that changes (this will be put in the ICsv)

ARRAY(str) in_extracted_sections.create(2) ;; The array (this will be put in the ICsv)
in_extracted_sections[0]="path"
in_extracted_sections[1]="file_locations"

in_settingsfile_content=
;[path]
;c:\test
;;
;[file_locations]
;1a*E:\__qm_testdirs\test_ini_1.txt
;2a*E:\__qm_testdirs\test_ini_2.txt

;; The temporary array that 'sets' ICsv
ARRAY(str) tmp_arr.create(2 in_extracted_sections.len)
ICsv v=CreateCsv()
str output_string
v.FromArray(tmp_arr)
v.Separator="|"
int nr=v.RowCount
int nc=v.ColumnCount
int r c

for i 0 in_extracted_sections.len
,findrx(in_settingsfile_content F"(?s)^\Q[{in_extracted_sections[i]}]\E(.+?)(?:^\[|\z)" 0 8 extracted_section_content 1)
,extracted_section_content.trim
,v.Cell(i 0)=in_extracted_sections[i]
,v.Cell(i 1)=extracted_section_content
,v.ToString(output_string)
,
out output_string

My question: Is the above way, the correct way to setup the ICsv object? (using temporary 2 dim Array "tmp_arr").
Or is there something faster/better I could with:
Code:
Copy      Help
ICsv v=CreateCsv()
#2
I would not use a temp array and FromArray. Can add rows to ICsv variable with its function AddRow2 or other functions. Repeat for each row.
#3
Macro Macro2239
Code:
Copy      Help
;out
int i
str in_settingsfile_content
str extracted_section_content ;; The string that changes (this will be put in the ICsv)

ARRAY(str) in_extracted_sections="path[]file_locations"

in_settingsfile_content=
;[path]
;c:\test
;;
;[file_locations]
;1a*E:\__qm_testdirs\test_ini_1.txt
;2a*E:\__qm_testdirs\test_ini_2.txt

ICsv v._create; v.Separator="|"
str output_string

for i 0 in_extracted_sections.len
,if(findrx(in_settingsfile_content F"(?s)^\Q[{in_extracted_sections[i]}]\E(.+?)(?:^\[|\z)" 0 8 extracted_section_content 1)<0)
,,extracted_section_content="ERROR"
,extracted_section_content.trim
,v.AddRow2(i in_extracted_sections[i] extracted_section_content)

v.ToString(output_string)
out output_string
#4
Thank you!
This makes more sense!
#5
Sorry about this, the example works for adding a row that has 2 colums.

It's about the following line
Code:
Copy      Help
v.AddRow2(i in_extracted_sections[i] extracted_section_content)

It has the following constraint:

Quote:#AddRow2(row $s1 [$s2]) ;;Adds row in 2-column CSV. Use row -1 to add to the end. Returns row index.

Adds or inserts row with 2 cells. Similar to the above functions. Use with 2-column CSV, when it is more convenient to pass 2 values than to use an array


Question

Is there a AddRow method I could use for adding more then 2 columns, what I mean is

Code:
Copy      Help
v.AddRow2(i string_1 string_2 int_1 int_2) ;; etc..etc...
#6
Look in the list. AddRowSA etc. Then look in Help, there is an example.
#7
Ok Thank you!

edit: I totally overlooked the green "Example" link (with dotted underline) in the helpfile, when clicked on it expanded with examples!


Forum Jump:


Users browsing this thread: 1 Guest(s)