WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: MW4 on November 10, 2016, 09:39:33 AM

Title: Variable spacing
Post by: MW4 on November 10, 2016, 09:39:33 AM
I have a line of text that is variable in length like this example:

Sometimes the text portion (A) is short 3 or 4 characters, and sometimes long 10-15 characters.
The numeric portions (N) can 10, 9, or 8 characters

AAAAAAAAA<a space>NNN,NNN.NN<a space>NNN,NNN.NN
1234567890                 1234567890   

Real example:

Thisline = "GOT1702 28,230.00 25,548.00"

I want to pull out each piece of data, but since it's variable in length I'm assuming that I need the numeric location of the spaces.
Unless there is an easier way...
                 
How can I pull out the two numeric positions like in the example above as:
Space 1 = 8
Space 2 = 18

I also have ones with 4 or 5 pieces of data too.

Guidance please :)


Title: Re: Variable spacing
Post by: td on November 10, 2016, 09:49:39 AM
Use the ItemExtract function with a space ' ' as the delimiter.
Title: Re: Variable spacing
Post by: MW4 on November 10, 2016, 12:52:12 PM
That get's me the first one...I need the nth ones as well.  How to nest?
Title: Re: Variable spacing
Post by: td on November 10, 2016, 01:44:42 PM
The Consolidated WIL Help file entry for the ItemExtract function states of the first parameter, "(i) index the position in list of the item to be selected."

Title: Re: Variable spacing
Post by: MW4 on November 10, 2016, 03:03:25 PM
the first piece of data may contain many spaces as it's textual in nature...The last two are variable length numbers or text indicating N/C.

Try this test

thisline = "FE - 50 Lb Cord N/C N/C"

IE1=itemextract(-1, thisline, " ")
Message("IE1",IE1)

IE2=itemextract(-2, thisline, " ")
Message("IE2",IE2)

IE3=itemextract(-3, thisline, " ")
Message("IE3",IE3)

Title: Re: Variable spacing
Post by: td on November 11, 2016, 10:05:15 AM
Why are you using negative numbers?   Other than -1 they don't belong in the first parameter.    There are numerous examples of using the item list related functions in the help file and Tech Database.  You might want to consider familiarizing yourself with how the item functions actually work by examining those examples.  Once you understand how they work and a apply a tiny bit of imagination, the path to solving your problem should be clear. 

Also note that there are other methods for solving your problem that don't involve using the item list functions, e.g., regular expressions and string functions.  However, the item list functions are likely the simplest approach.