## String Functions - Returns a specified segment from a string

7 - Meteor

Issue - Need help in string function to be used

Sample data

Case -1  : 66-YY-ZZZZ-AAAAAA-123
Case -2 : MX-YY-AAAA-ZZZZZZ-596
Case -3 : 66|YYYYYYY|ZZZZZZZZ|AAAAAAAAA|1|12|11234|X

Requirement

I need to extract "AAAAAA" from Case-1 , "AAAA" from case-2 and "AAAAAAAA" from case-3. This is the mix of the data I have in my file

in other languages we can extract the 4th segment from case-1 after the '-' , 3rd segment from case-2 after '-' and in case 3, 4th segment after '|'.

How do i replicate it in Alteryx.

12 - Quasar

Are you trying to extract any time that it says "A*" or are you looking for those specific spots in your string and want to extract whatever is there?

7 - Meteor

Clarification - it is not always 'A' . It is just the position. it would be a alphanumeric combination.

12 - Quasar

I am sorry, but the other clarification I guess I would need is, is the position you need to find based on case number or are those just examples of record ids? Specifically, in any given string, how do I know if I need to look in the third or fourth spot?

7 - Meteor

That is a good question. Sorry it was not very clear

Case 1 and case 2 is when substring("string",1,2)  = '66' and (substring("string",3,1) = "-" OR substring("string",3,1) = "|")

Case 3 is when substring("string",1,2)  = 'MX'

7 - Meteor

update

That is a good question. Sorry it was not very clear

Case 1 and case 3 is when substring("string",1,2) = '66' and (substring("string",3,1) = "-" OR substring("string",3,1) = "|")

Case 2 is when substring("string",1,2) = 'MX'

7 - Meteor

I figured out a round about solution using a combination of string functions

Step 1 :Use ReplaceChar(x, y, z): to replace special char with spaces

Step2 : Use GetWord(String, n) to extract the right word from the above result after spaces

12 - Quasar

okay so the quickest solution I could come up with is attached. I just parse everything and then you would build your own logic around selecting the record (segment) that you need. I imagine you can do this with REGEX as well, but I am still a little fuzzy on which segments you are needing to grab. Is that excel syntax that you posted?

7 - Meteor