Variable spacing

Started by MW4, November 10, 2016, 09:39:33 AM

Previous topic - Next topic

MW4

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 :)



td

Use the ItemExtract function with a space ' ' as the delimiter.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

MW4

That get's me the first one...I need the nth ones as well.  How to nest?

td

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."

"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

MW4

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)


td

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.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade