| View previous topic :: View next topic |
| Author |
Message |
Aslan Valued Contributor


Joined: 31 May 2001 Posts: 589 Location: Memphis, TN USA
|
Posted: Tue Apr 04, 2006 3:59 pm Post subject: Parsing Fixed Width strings |
|
|
| Anyone had any luck parsing fixed width strings? |
|
| Back to top |
|
 |
Dr. Dread Professional Member


Joined: 03 Aug 2001 Posts: 1065 Location: Copenhagen, Denmark
|
Posted: Tue Apr 04, 2006 5:05 pm Post subject: |
|
|
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 |
|
 |
Aslan Valued Contributor


Joined: 31 May 2001 Posts: 589 Location: Memphis, TN USA
|
Posted: Wed Apr 05, 2006 3:16 pm Post subject: |
|
|
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 |
|
 |
Dr. Dread Professional Member


Joined: 03 Aug 2001 Posts: 1065 Location: Copenhagen, Denmark
|
Posted: Wed Apr 05, 2006 9:44 pm Post subject: |
|
|
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 |
|
 |
Aslan Valued Contributor


Joined: 31 May 2001 Posts: 589 Location: Memphis, TN USA
|
Posted: Wed Apr 05, 2006 11:43 pm Post subject: |
|
|
| They're all spaces @chr(32) |
|
| Back to top |
|
 |
Serge Professional Member


Joined: 04 Mar 2002 Posts: 1480 Location: Australia
|
Posted: Thu Apr 06, 2006 1:37 am Post subject: |
|
|
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 |
|
 |
uvedese Contributor


Joined: 21 Jan 2006 Posts: 169 Location: Spain
|
Posted: Fri Apr 07, 2006 4:07 pm Post subject: |
|
|
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 |
|
 |
Aslan Valued Contributor


Joined: 31 May 2001 Posts: 589 Location: Memphis, TN USA
|
Posted: Fri Apr 07, 2006 9:25 pm Post subject: |
|
|
| What would you suggest I use for the Character separator? |
|
| Back to top |
|
 |
uvedese Contributor


Joined: 21 Jan 2006 Posts: 169 Location: Spain
|
Posted: Sat Apr 08, 2006 8:45 am Post subject: |
|
|
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  |
|
| Back to top |
|
 |
Skit3000 Admin Team

Joined: 11 May 2002 Posts: 2166 Location: The Netherlands
|
Posted: Sat Apr 08, 2006 5:59 pm Post subject: |
|
|
You might try Dr. Dread's string.dll to do this. 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 |
|
 |
|