Page 1 of 1 1
Topic Options
#157925 - 2006-02-27 09:41 PM Get specific values from a ; separated string
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Call me stupid but I just can't seem to get my brain to figure this out.

The case:
Several times a week we get a feed for one of our magazines from an FTP server. Currently we manually process the data in the received files to the format we can use for our office application. The file could contain up to 10.000+ lines so processing it is a time consuming job.

This is an example of what the contents of the file looks like:

Quote:


abdc;some crap here;1234
1234;5678
1234abcd;some crap here;some more crap here;abcd1234





As you can see it's values separated by a ;. I only need the first and the last value from each line all other stuff is of no importance to us. Just splitting it on the ; wont do cause there could be just two values but there could also be 20 values.
If it would be an array my problems are over but unfortunately it's not.

Readline like this:
Code:

$1 = Open (1, "d:\test.csv",2)
$2 = ReadLine (1)
$3 = VarType ($rc)
?$2
?$3
Sleep 3



returns a string. Is there any way to get only the first and the last value into separate vars?
Been looking at this for some hours now and just can’t get a solution.

Like said maybe a stupid question but he we are all entitled to ask a stupid questions now and then.


Edited by Mart (2006-02-27 09:42 PM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#157926 - 2006-02-27 09:46 PM Re: Get specific values from a ; separated string
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Maybe you could split the input line on ";", then do this:

$array = split($line,";")

?"first = " $array[0]
?"last=" $array[UBound($array)]

Top
#157927 - 2006-02-27 10:25 PM Re: Get specific values from a ; separated string
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Sweet
I’ll make some new friends with this among the people that manually process the files when I'm back at work tomorrow.
Tanx shawn, I knew it would not be that hard but I just could not see it clear anymore after several hours of starring at it.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#157928 - 2006-02-27 10:38 PM Re: Get specific values from a ; separated string
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Just make sure you add tons of error checking before doing this - check for things like null input strings before splitting - most important, make sure the UBound is > 0 before proceeding. This kind of processing deserves much error clecking.
Top
#157929 - 2006-02-27 10:52 PM Re: Get specific values from a ; separated string
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Yeah I know. Especially if it is about renaming pictures to be used on our internet site and by our DTP department. These are pictures of automobiles and motorcycles belonging to adds on our site and in one of our magazines so it is crucial that the correct picture gets renamed to the correct new name and the other way around after the processing for the site and by our DTP guys has been completed.
I’ll definitely add checks for zero input, var type, weird input not corresponding to the required input, etc….
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#157930 - 2006-02-27 11:01 PM Re: Get specific values from a ; separated string
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
I knew you knew that ... but - did you know that I knew that you knew that ?
Top
#157931 - 2006-02-27 11:06 PM Re: Get specific values from a ; separated string
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Yep. I know that you know that I know that.

LOL

BTW: anybody reading this will now know that I know that you know that I know that.


Edited by Mart (2006-02-27 11:07 PM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#157932 - 2006-02-27 11:54 PM Re: Get specific values from a ; separated string
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
think you got it wrong.
bet you ment to say that you know that shawn knew that you knew.

problem is, shawn asked did you know and that's a question you didn't answer
_________________________
!

download KiXnet

Top
#157933 - 2006-02-28 01:17 AM Re: Get specific values from a ; separated string
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
ROFLMAO - You non native English speakers giving each other Hell over English.
Top
#157934 - 2006-02-28 11:00 AM Re: Get specific values from a ; separated string
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Ok, ok, ok you win.
Now at least everybody that reads this knows it. Maybe they knew it already but then they just got reminded to the fact that they already knew it.

LOL

Getting on topic again.
Just build in some checks for empty input, wrong input and var type and it runs around 6 seconds on +/- 7500 lines. Currently the manual translation takes at least 30 minutes using some fancy stuff in excel and it errors out like 10 times. Just made some new friends when it showed them my current (under construction) solution.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#157935 - 2006-02-28 07:38 PM Re: Get specific values from a ; separated string
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Great to hear Mart. This is the sort of thing that really helps to bring out for others the power of scripting for daily or rarely done tasks. Reducing the time and effort and hopefully reducing the chances of error as well by manual methods.
Top
#157936 - 2006-03-01 12:33 AM Re: Get specific values from a ; separated string
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4403
Loc: New Jersey
So, just what is it we're all supposed to know now? I am not knowing of this...
_________________________
Actually I am a Rocket Scientist! \:D

Top
#157937 - 2006-03-01 01:07 AM Re: Get specific values from a ; separated string
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Your supposed to know that Mart knew I knew he knew I knew he knew.
Top
#157938 - 2006-03-01 01:10 AM Re: Get specific values from a ; separated string
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I guess it's the knowledge that "this" kind of processing deserves lots of error checking.
and that shawn and mart both knew this and they knew that they both knew it.

what is the special kind referred to as "this", I don't know.
_________________________
!

download KiXnet

Top
#157939 - 2006-03-07 03:39 AM Re: Get specific values from a ; separated string
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4403
Loc: New Jersey
Oh...

I knew that!

I have some (fairly specific) parsing UDFs that might be good example logic for error checking. I use it for parsing command-line arguments, including sub-parameters. I'll pass it on to DOC to post in the Code How-To section when i have a chance.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 581 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.069 seconds in which 0.027 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org