Find the middle elemet of a string


#1

Hi.

I have some strings such as:

001 00001 POWER SEAT EA 10.0000 I
002 000YZ TRACK ASSY, SEAT OUTERDZ 1.0000 II
003 0X000 HOUSING SUB-ASSY, POWER SEAT, NO.1EA 12.0217 III

Each line contains Line Number, Item Number, Description, Unit of Mesure, Price and Price Type.

The problem is sometimes there is a whitespace between “Description” and “Unit of Mesure” (e.g. SEAT EA), and sometimes there isn’t (e.g. OUTERDZ)

Is there any way to find Unit of Measure from the original string and extract like:

EA
DZ
EA

Thank you!

Find the middle elemet of a string.xaml (9.1 KB)


#2

This is a little tricky. May I suggest using a Regex pattern maybe.

regexPattern = "[A-Z]{2}(?=(\s[0-9]{1,2}\.[0-9]{4}))"
unit = System.Text.RegularExpressions.Regex.Match(text, regexPattern).Value

For the pattern, I used a look ahead to see if there is a space and the digits so it matches with the 2 letters before it.

Hopefully that works or gets you in a good direction.

Regards.


#3

Thanks for replying.

I tried your Regex pattern but it returned a blank value…
Capture

I have attached my workflow. I appreciate if you could tell me what I’m missing…

Find the middle elemet of a string_v2.xaml (12.4 KB)

Thanks!


#4

Sorry about that @anna100, I used the wrong character for look ahead

Try this instead: "[A-Z]{2}(?=(\s[0-9]{1,2}\.[0-9]{4}))"

?= is proper characters.

Regards.


#5

It worked! Thanks!!:grin: