AutoHotkey Community

It is currently May 26th, 2012, 8:24 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 53 posts ]  Go to page Previous  1, 2, 3, 4  Next
Author Message
 Post subject:
PostPosted: June 21st, 2008, 7:44 pm 
Offline

Joined: April 18th, 2008, 7:57 am
Posts: 1390
Location: The Interwebs
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?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 21st, 2008, 7:50 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
@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]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 21st, 2008, 7:55 pm 
Offline

Joined: March 19th, 2007, 12:43 am
Posts: 532
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 21st, 2008, 8:03 pm 
Offline

Joined: April 18th, 2008, 7:57 am
Posts: 1390
Location: The Interwebs
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 21st, 2008, 8:10 pm 
Offline

Joined: March 19th, 2007, 12:43 am
Posts: 532
Thanks for your note, but the only separators that i think are worth looking into are: coma, space and tab.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 21st, 2008, 10:23 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
Quote:
Don't you think that 2 loops is a bit messy for something like this:D ?
What can I say, it was late :wink: [/quote]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 23rd, 2008, 6:43 pm 
Offline

Joined: March 19th, 2007, 12:43 am
Posts: 532
Update, added a search function.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 23rd, 2008, 9:41 pm 
Offline

Joined: March 19th, 2007, 12:43 am
Posts: 532
Update, added CSV_exists()


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 23rd, 2008, 9:54 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
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 :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 23rd, 2008, 10:02 pm 
Offline

Joined: March 19th, 2007, 12:43 am
Posts: 532
CSV_exists() is much faster. If you'll look at how those functions get their result you'll see what i mean :wink: .

Hmmmm, you are right, i don't get it why is blank. :?
I'll look into it.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 23rd, 2008, 10:29 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
In _find change
Code:
   if (row = "" && column = "") {

to
Code:
   if (row = "0" && column = "0") {
and it returns 5,2 as advertised :-)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 23rd, 2008, 10:41 pm 
Offline

Joined: March 19th, 2007, 12:43 am
Posts: 532
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) :oops: .

Here is what i did:
Code:
            if (regExMatch(__matrix%i%_%A_Index%, value . "\R?$")) {
               return % i + offset_x . "," . A_Index + offset_y                ;%
            }


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 24th, 2008, 7:22 am 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
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)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 24th, 2008, 9:03 pm 
Offline

Joined: March 19th, 2007, 12:43 am
Posts: 532
Update, added CSV_sort()


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 25th, 2008, 4:34 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
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)


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 53 posts ]  Go to page Previous  1, 2, 3, 4  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 19 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group