AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

simplified csv operations.
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Krogdor



Joined: 18 Apr 2008
Posts: 1145
Location: The Interwebs

PostPosted: Sat Jun 21, 2008 6:44 pm    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
HugoV



Joined: 27 May 2007
Posts: 650

PostPosted: Sat Jun 21, 2008 6:50 pm    Post subject: Reply with quote

@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
View user's profile Send private message
neXt



Joined: 18 Mar 2007
Posts: 463

PostPosted: Sat Jun 21, 2008 6:55 pm    Post subject: Reply with quote

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
View user's profile Send private message
Krogdor



Joined: 18 Apr 2008
Posts: 1145
Location: The Interwebs

PostPosted: Sat Jun 21, 2008 7:03 pm    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
neXt



Joined: 18 Mar 2007
Posts: 463

PostPosted: Sat Jun 21, 2008 7:10 pm    Post subject: Reply with quote

Thanks for your note, but the only separators that i think are worth looking into are: coma, space and tab.
Back to top
View user's profile Send private message
HugoV



Joined: 27 May 2007
Posts: 650

PostPosted: Sat Jun 21, 2008 9:23 pm    Post subject: Reply with quote

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]
Back to top
View user's profile Send private message
neXt



Joined: 18 Mar 2007
Posts: 463

PostPosted: Mon Jun 23, 2008 5:43 pm    Post subject: Reply with quote

Update, added a search function.
Back to top
View user's profile Send private message
neXt



Joined: 18 Mar 2007
Posts: 463

PostPosted: Mon Jun 23, 2008 8:41 pm    Post subject: Reply with quote

Update, added CSV_exists()
Back to top
View user's profile Send private message
HugoV



Joined: 27 May 2007
Posts: 650

PostPosted: Mon Jun 23, 2008 8:54 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
neXt



Joined: 18 Mar 2007
Posts: 463

PostPosted: Mon Jun 23, 2008 9:02 pm    Post subject: Reply with quote

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. Confused
I'll look into it.
Back to top
View user's profile Send private message
HugoV



Joined: 27 May 2007
Posts: 650

PostPosted: Mon Jun 23, 2008 9:29 pm    Post subject: Reply with quote

In _find change
Code:
   if (row = "" && column = "") {

to
Code:
   if (row = "0" && column = "0") {
and it returns 5,2 as advertised Smile
Back to top
View user's profile Send private message
neXt



Joined: 18 Mar 2007
Posts: 463

PostPosted: Mon Jun 23, 2008 9:41 pm    Post subject: Reply with quote

Yeah, but i just discovered another bug, every last element in the array has a new line attached to it and causes mismatch Sad . I did fix it, but i was hoping to avoid using RegEx (they are slower than regular functions) Embarassed .

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
View user's profile Send private message
HugoV



Joined: 27 May 2007
Posts: 650

PostPosted: Tue Jun 24, 2008 6:22 am    Post subject: Reply with quote

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
View user's profile Send private message
neXt



Joined: 18 Mar 2007
Posts: 463

PostPosted: Tue Jun 24, 2008 8:03 pm    Post subject: Reply with quote

Update, added CSV_sort()
_________________
simplified csv - easy way to handle csv files.
Back to top
View user's profile Send private message
HugoV



Joined: 27 May 2007
Posts: 650

PostPosted: Wed Jun 25, 2008 3:34 pm    Post subject: Reply with quote

Is it me or does your sort don't actually do any sorting Question
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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group