Skip to main content
Solved

Split text into parts based on text number

  • April 18, 2024
  • 4 replies
  • 140 views

pauld
Contributor
Forum|alt.badge.img+1

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:

 

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

4 replies

becchr
Influencer
Forum|alt.badge.img+32
  • 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+35
  • 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+35
  • 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