General Question - Array+ Increments - Forum

Forum Navigation
You need to log in to create posts and topics.

General Question - Array+ Increments

Hi, I'm a bit rusty with Neobook. How do I go about exporting all the array values after using the "StrParse" command ?

I don't want to use individual entries to write out the data.

Example

FileWrite "!C:\Users\pc\Desktop\filtered_plist.txt" "Append" "[raw_plist_filtered_array1]"
FileWrite "!C:\Users\pc\Desktop\filtered_plist.txt" "Append" "[raw_plist_filtered_array2]"

I want to loop through the total number of arrays ... let's say 54 arrays and have it export all of the data to a text file.  I'm assuming I would need to use an increment command that captures the next array in sequence until all the arrays are exported based on the total array count.

How do I go about coding that ..

Thanks!

First you have to know how many values the array has in total. Then, you can use the "Loop" command to save the data.

Loop "1" "[Total_Numbers]" "[Counter]"
     FileWrite "C:\Users\pc\Desktop\filtered_plist.txt" "Append" "[raw_plist_filtered_array[Counter]]"
EndLoop

Remember that using "Append" in the "FileWrite" command appends data to the end of the file. In this way, if you rerun the "Loop" you will add more data instead of replacing it.

If you want to avoid this, you can find the file and if it exists delete it before starting the "Loop" command.

FileExists "C:\Users\pc\Desktop\filtered_plist.txt" "[File_Found]"
If "[File_Found]" "=" "True"
     FileErase "C:\Users\pc\Desktop\filtered_plist.txt"
EndIf

I hope this helps.

Vadim has reacted to this post.
Vadim

Hi, I was on a mission to find my post :) .. Hard to find it on here. Finally found it by typing in "increment".

Thanks for the swift response, worked great!

####

I noticed that the array data gets exported as a single line of information. Is there a way to export the array data 1 per line without having to filter the data with "StrReplace" to add my own delimiter.

For example the line feed option. ( #10 )

I'm doing it like this which works but I would have to continue using "StrReplace" until I add the line feed delimiter otherwise.

I'm curious to know if I can export the array data 1 per line without delimiters via the loop command ect ..?

.DELIMITERS: ; | ? | \ | ^ | $ | ! | ( | ) | & | # | * | @ | PIPE CHARACTER

FileExists "C:\Users\pc\Desktop\testing_4.txt" "[status]"

If "[status]" "=" "true"

FileErase "!C:\Users\pc\Desktop\testing_4.txt"

Else

EndIf

.Import "plist_sample.txt" data into variable.
FileRead "!C:\Users\pc\Desktop\plist_sample.txt" "All" "[raw_plist]"

.Remove junk data from the source data. -> ['
StrReplace "[raw_plist]" "[#91]'" "" "[raw_plist_filtered_1]" ""

.Replace anchor character(s) -> ', with a custom delimiter.
StrReplace "[raw_plist_filtered_1]" "', " "@" "[raw_plist_filtered_2]" ""

.Parse plist @ delimiter to obtain array count.
StrParse "[raw_plist_filtered_2]" "@" "[raw_plist_filtered_2_array]" "[array_count_total]"

.Loop through arrays and output values to .txt
Loop "1" "[array_count_total]" "[Counter]"
FileWrite "!C:\Users\pc\Desktop\testing_4.txt" "Append" "[raw_plist_filtered_2_array[Counter]]"
EndLoop

Thanks!

Hi @mediasurfer,

Hi, I was on a mission to find my post :) .. Hard to find it on here. Finally found it by typing in "increment".

Sorry, I moved it to the right forum section. Note that you can manage the forum by using the bottom links to show only "unread" elements. Just click "Mark all read" in the main forum page and you will notice every new post very easily.

Regards.

@mediasurfer

Is there a way to export the array data 1 per line without having to filter the data with "StrReplace" to add my own delimiter.
For example the line feed option. ( #10 )

The new line (CRLF) code in Windows is [#13][#10] ... so modify the code suplied by @cn_iceman like so ...

FileWrite "C:\Users\pc\Desktop\filtered_plist.txt" "Append" "[raw_plist_filtered_array[Counter]][#13][#10]"

 

I'm not really clear on your intention here. Is your source file, plist_sample.txt, a single string in a text file or is it a multi line text file where each line already has a CR?

Could this work...?

If you have a parsed variable and appending a file through a Loop you shouldn't need an LF or CR in your variable.
If your source file is multi line, you can replace all of the left brackets "[" with nothing "" and that's fine  but if you want to replace all commas "," with a delimiter of "@" and parse by that, any CRs in your file will make extra lines. Otherwise you could replace your left brackets with nothing, replace your commas with carriage return [#13] and then write the resulting variable to a file in one line. Even add a line feed [#10] if you want.

.Import "plist_sample.txt" data into variable.
FileRead "!C:\Users\pc\Desktop\plist_sample.txt" "All" "[raw_plist]"

.Remove junk data from the source data. -> ['
StrReplace "[raw_plist]" "[#91]'" "" "[raw_plist_filtered_1]" ""

.Replace anchor character(s) -> ', with a carrage return [#13].
StrReplace "[raw_plist_filtered_1]" "', " "[#13]" "[raw_plist_filtered_2]" ""

FileWrite "!C:\Users\pc\Desktop\testing_4.txt" "All" "[raw_plist_filtered_2]"

 

Also, to avoid erasing the file you could try:

FileWrite "!C:\Users\pc\Desktop\testing_4.txt" "All" "[raw_plist_filtered_2_array1]"
Loop "2" "[array_count_total]" "[Counter]"
FileWrite "!C:\Users\pc\Desktop\testing_4.txt" "Append" "[raw_plist_filtered_2_array[Counter]]"
EndLoop