| View previous topic :: View next topic |
| Author |
Message |
Krogdor
Joined: 18 Apr 2008 Posts: 1145 Location: The Interwebs
|
Posted: Sat Jun 21, 2008 6:44 pm Post subject: |
|
|
| Code: | loop parse, A_LoopField, %delimiter%
{
if(r_row = 1)
r_col++
__matrix%r_row%_%A_Index% = %A_LoopField%
} |
Isn't that not going to be able to properly handle CSV? For example:
| Quote: | | this,"might, not", work? |
|
|
| Back to top |
|
 |
HugoV
Joined: 27 May 2007 Posts: 650
|
Posted: Sat Jun 21, 2008 6:50 pm Post subject: |
|
|
@krogdor, note the IF statement | Code: | if r_delimiter = ,
delimiter = CSV | I tried it and it does work. I simply made two loops one for CSV one for other delimiters, but this works as well.[/code] |
|
| Back to top |
|
 |
neXt
Joined: 18 Mar 2007 Posts: 463
|
Posted: Sat Jun 21, 2008 6:55 pm Post subject: |
|
|
HugoV nice catch, updated. Thanks!
| Quote: | | I simply made two loops one for CSV one for other delimiters, but this works as well. |
Don't you think that 2 loops is a bit messy for something like this:D ?
Krogdor I tested such statements and it works fine.
Something like this will also work thanks to Rhys's function.
| Code: |
var = this, is "a test"
CSV_write(1, 1, var)
|
BTW, i tested this on a 2000 line CSV file, take a second to read it, but after works very smooth. |
|
| Back to top |
|
 |
Krogdor
Joined: 18 Apr 2008 Posts: 1145 Location: The Interwebs
|
Posted: Sat Jun 21, 2008 7:03 pm Post subject: |
|
|
| HugoV wrote: | @krogdor, note the IF statement | Code: | if r_delimiter = ,
delimiter = CSV | I tried it and it does work. I simply made two loops one for CSV one for other delimiters, but this works as well.[/code] |
Ah, didn't see that. Sorry.
Although, using a delimiter other than a comma will force it to be simply delimited by it, and not contained by quotes or anything (for example with a delimiter of ";", this;"will; not";work)
I dont know if you care about other delimiters enough to fully implement them, but if you do, DerRaphael wrote a function for just that purpose:
http://www.autohotkey.com/forum/viewtopic.php?t=32938 |
|
| Back to top |
|
 |
neXt
Joined: 18 Mar 2007 Posts: 463
|
Posted: Sat Jun 21, 2008 7:10 pm Post subject: |
|
|
| Thanks for your note, but the only separators that i think are worth looking into are: coma, space and tab. |
|
| Back to top |
|
 |
HugoV
Joined: 27 May 2007 Posts: 650
|
Posted: Sat Jun 21, 2008 9:23 pm Post subject: |
|
|
| Quote: | | Don't you think that 2 loops is a bit messy for something like this:D ? | What can I say, it was late [/quote] |
|
| Back to top |
|
 |
neXt
Joined: 18 Mar 2007 Posts: 463
|
Posted: Mon Jun 23, 2008 5:43 pm Post subject: |
|
|
| Update, added a search function. |
|
| Back to top |
|
 |
neXt
Joined: 18 Mar 2007 Posts: 463
|
Posted: Mon Jun 23, 2008 8:41 pm Post subject: |
|
|
| Update, added CSV_exists() |
|
| Back to top |
|
 |
HugoV
Joined: 27 May 2007 Posts: 650
|
Posted: Mon Jun 23, 2008 8:54 pm Post subject: |
|
|
MsgBox % CSV_find("e") returns nothing with your test file? shouldn't it return 5,2? MsgBox % CSV_find("e",5) does return 2... Also if you have the _find what use is the Exist? If _find return anything it exists if it's empty it doesn't  |
|
| Back to top |
|
 |
neXt
Joined: 18 Mar 2007 Posts: 463
|
Posted: Mon Jun 23, 2008 9:02 pm Post subject: |
|
|
CSV_exists() is much faster. If you'll look at how those functions get their result you'll see what i mean .
Hmmmm, you are right, i don't get it why is blank.
I'll look into it. |
|
| Back to top |
|
 |
HugoV
Joined: 27 May 2007 Posts: 650
|
Posted: Mon Jun 23, 2008 9:29 pm Post subject: |
|
|
In _find change | Code: | | if (row = "" && column = "") { |
to | Code: | | if (row = "0" && column = "0") { | and it returns 5,2 as advertised  |
|
| Back to top |
|
 |
neXt
Joined: 18 Mar 2007 Posts: 463
|
Posted: Mon Jun 23, 2008 9:41 pm Post subject: |
|
|
Yeah, but i just discovered another bug, every last element in the array has a new line attached to it and causes mismatch . I did fix it, but i was hoping to avoid using RegEx (they are slower than regular functions) .
Here is what i did:
| Code: | if (regExMatch(__matrix%i%_%A_Index%, value . "\R?$")) {
return % i + offset_x . "," . A_Index + offset_y ;%
} |
|
|
| Back to top |
|
 |
HugoV
Joined: 27 May 2007 Posts: 650
|
Posted: Tue Jun 24, 2008 6:22 am Post subject: |
|
|
I use StringTrimRight, cell_XY, cell_XY, 1 ; trim trailing , or `n or perhaps
include an ignore character in your loop: loop parse, r_file, `n
(note `n could be a delimiter in a multiline CSV cell.
loop parse, r_file, `r, `n might be better) |
|
| Back to top |
|
 |
neXt
Joined: 18 Mar 2007 Posts: 463
|
Posted: Tue Jun 24, 2008 8:03 pm Post subject: |
|
|
Update, added CSV_sort() _________________ simplified csv - easy way to handle csv files. |
|
| Back to top |
|
 |
HugoV
Joined: 27 May 2007 Posts: 650
|
Posted: Wed Jun 25, 2008 3:34 pm Post subject: |
|
|
Is it me or does your sort don't actually do any sorting
I don't see the difference between before/after sort when I do this: | Code: | set_CSV("test.csv")
CSV_sort(2)
finalize_CSV(1) |
|
|
| Back to top |
|
 |
|