Skip to main content
Solved

Split text into parts based on text number


pauld
Contributor
Forum|alt.badge.img+1
  • Contributor

Hi, I have a text string that looks something like this…

LOT 4-6 DP 287 SEC 2-3 SO 345152 

I have a regex “(LOT \d+[\s?&-]\d+ DP \d+ ){1,}”  that grabs the LOT 4-6 DP 287 from the text line.

How can I split the 4-6 into separate attributes so I end up with 

  • Lot 4 DP 287
  • Lot 5 DP 287
  • Lot 6 DP 287

I could do it with a testfilter but there are unknown combinations. 1-12, 60-62, 78-82 etc

Any help is greatly appreciated.

Regards, Paul

Best answer by jkr_wrk

First use a StringSearcher to Regex Search the LOT_RANGE (second part of your LOT_CODE)

Then Split the LOT_RANGE on the minus to get the LOT_LIST containing 2 values

Then calculate the length of the LOT (RANGE_AMOUNT)=RANGE_LIST{1}-RANGE_LIST{0}+1

Then clone your features by RANGE_AMOUNT and store the RANGE_OFFSET (clone-index)

Then make the LOT_NUM=RANGE_LIST{0}+RANGE_OFFSET

And finaly you could StringReplace the LOT_RANGE in your string with the LOT_NUM. But don't know if you want to do it like that:

Result:

 

View original
Did this help you find an answer to your question?

4 replies

becchr
Influencer
Forum|alt.badge.img+26
  • Influencer
  • April 18, 2024

hi, other ways are possible and probably more efficient, but this might get you in the right direction?

The value LOT 4-6 DP 287 is in an attribute ‘test’ to start with, ends up with 3 features:

 


jkr_wrk
Influencer
Forum|alt.badge.img+29
  • Best Answer
  • April 18, 2024

First use a StringSearcher to Regex Search the LOT_RANGE (second part of your LOT_CODE)

Then Split the LOT_RANGE on the minus to get the LOT_LIST containing 2 values

Then calculate the length of the LOT (RANGE_AMOUNT)=RANGE_LIST{1}-RANGE_LIST{0}+1

Then clone your features by RANGE_AMOUNT and store the RANGE_OFFSET (clone-index)

Then make the LOT_NUM=RANGE_LIST{0}+RANGE_OFFSET

And finaly you could StringReplace the LOT_RANGE in your string with the LOT_NUM. But don't know if you want to do it like that:

Result:

 


jkr_wrk
Influencer
Forum|alt.badge.img+29
  • April 18, 2024

You @becchr beat me on time. Should have refreshed the page.

 

Almost exactly the same solution. My AttributeCreator_5 is integrated in your StringReplacer.

And my StringSearcher is only looking for Ranges after the word LOT.

I can imagine somewhere down the line you want every part of the LOT_CODE to be in separate columns. So you would split everything in the right column to start, but if this is the final result, this is a solution.


pauld
Contributor
Forum|alt.badge.img+1
  • Author
  • Contributor
  • April 18, 2024

Thank you both for your time. Exactly what I was after and would have taken me days.

You guys rock!

Regards, Paul


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings