forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Parsing Fixed Width strings

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help
View previous topic :: View next topic  
Author Message
Aslan
Valued Contributor
Valued Contributor


Joined: 31 May 2001
Posts: 589
Location: Memphis, TN USA

PostPosted: Tue Apr 04, 2006 3:59 pm    Post subject: Parsing Fixed Width strings Reply with quote

Anyone had any luck parsing fixed width strings?
Back to top
View user's profile Send private message Send e-mail
Dr. Dread
Professional Member
Professional Member


Joined: 03 Aug 2001
Posts: 1065
Location: Copenhagen, Denmark

PostPosted: Tue Apr 04, 2006 5:05 pm    Post subject: Reply with quote

Are you thinking of strings with fixed-width fields? Then @substr() should work fine...

Greetz
Dread

_________________
~~ Alcohol and calculus don't mix... Don't drink and derive! ~~

String.DLL * advanced string processing
Back to top
View user's profile Send private message
Aslan
Valued Contributor
Valued Contributor


Joined: 31 May 2001
Posts: 589
Location: Memphis, TN USA

PostPosted: Wed Apr 05, 2006 3:16 pm    Post subject: Reply with quote

My problem is that I don't know the widths. I'm importing foreign data.

Is there a way to detect the widths? Plus each field probably has a different width.

What I'm trying to do is get data from a command line app that outputs in fixed width table format. It seems that for each column it uses the widest
entry in that column plus a certain amount of blank space to determine the width. At first I though it used tabs but trying to parse it using @tab() as a field separator doesn't work.

I even tried using the String.dll

%A = @string(parse,%%item,1,@tab(),1)
%B = @string(parse,%%item,2,@tab(),1)
...etc

This didn't work either
Back to top
View user's profile Send private message Send e-mail
Dr. Dread
Professional Member
Professional Member


Joined: 03 Aug 2001
Posts: 1065
Location: Copenhagen, Denmark

PostPosted: Wed Apr 05, 2006 9:44 pm    Post subject: Reply with quote

Of course you need to find out what it used as blankspace chars, otherwise you will not be able to parse
the content if fields are of variable width. Step through a line and let @ASC() tell you what's in there.

Greetz
Dread

_________________
~~ Alcohol and calculus don't mix... Don't drink and derive! ~~

String.DLL * advanced string processing
Back to top
View user's profile Send private message
Aslan
Valued Contributor
Valued Contributor


Joined: 31 May 2001
Posts: 589
Location: Memphis, TN USA

PostPosted: Wed Apr 05, 2006 11:43 pm    Post subject: Reply with quote

They're all spaces @chr(32)
Back to top
View user's profile Send private message Send e-mail
Serge
Professional Member
Professional Member


Joined: 04 Mar 2002
Posts: 1480
Location: Australia

PostPosted: Thu Apr 06, 2006 1:37 am    Post subject: Reply with quote

could you use the idea that if it has more than, say, 2 or 3 spaces then it is the delimiter?

eg. if a section has more than, say, 3 spaces, replace that section with a | and then parse it using | as the delimiter

just an idea

serge

_________________
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
uvedese
Contributor
Contributor


Joined: 21 Jan 2006
Posts: 169
Location: Spain

PostPosted: Fri Apr 07, 2006 4:07 pm    Post subject: Reply with quote

Hi Aslan.

You can use my argDSU.dsu...

SINTAXIS

@arg(count,<argumentos>,[<carácter separador>])
@arg(item,<argumentos>,<nº del argumento>,[<carácter separador>])
@arg(extract,<argumentos>,[<carácter separador>])
@arg(delete,<argumentos>,<nº del argumento>,[<carácter separador>])
@arg(insert,<argumentos>,<nº del argumento>,<argumento a insertar>,[<separador>])
@arg(put,<argumentos>,<número del argumento>,<argumento sustituto>,[<separador>])
@arg(position,<argumentos>,<número del argumento>,[<separador>])

download this from:
http://vds.uvedese.es/index.php?option=com_content&task=view&id=130&Itemid=52


visit: http://www.uvedese.es


Last edited by uvedese on Wed Apr 02, 2008 9:05 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
Aslan
Valued Contributor
Valued Contributor


Joined: 31 May 2001
Posts: 589
Location: Memphis, TN USA

PostPosted: Fri Apr 07, 2006 9:25 pm    Post subject: Reply with quote

What would you suggest I use for the Character separator?
Back to top
View user's profile Send private message Send e-mail
uvedese
Contributor
Contributor


Joined: 21 Jan 2006
Posts: 169
Location: Spain

PostPosted: Sat Apr 08, 2006 8:45 am    Post subject: Reply with quote

Test to find a sequence of characters that is repeated. If the size of the fields is fixed that sequence each certain number of characters will repeat...

It can give result Wink
Back to top
View user's profile Send private message Visit poster's website
Skit3000
Admin Team


Joined: 11 May 2002
Posts: 2166
Location: The Netherlands

PostPosted: Sat Apr 08, 2006 5:59 pm    Post subject: Reply with quote

You might try Dr. Dread's string.dll to do this. Smile I have not tested this code, but I think it might work for you. Be sure to create a little loop to parse the output code of your command line program line by line.

Code:
option fieldsep,@tab()
%%string = "put your string-to-be-parsed here"
%%string = @string(RegxReplace, %%string, "\s{2,}", @tab())
parse "%%column1;%%column2;%%column3",%%string

_________________
[ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group