Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
richard_chilvers
Specialist
Specialist

Extracting a substring

I have a string such as:

   

08000355058|,803,|, National|,860,|, D1524|,881,|, M1529|,881,|, M1530|,881,|, M1531|,881,|

The 8** digits (eg. 803) are fixed identifiers to identify the values they follow.

In this example I want to ignore the '803' and '860' identifiers and preserve the '881' codes eg. D1524, M15329, M1530 etc.

I can use SUBFIELD to unpack the values during a LOAD, but I'm not clear how to get rid of the preceding string first, which I'm not interested in.

Any suggestions?

Thanks

1 Solution

Accepted Solutions
sunny_talwar

May be this:

Table:

LOAD Trim(SubField(NewField, '|,', 1)) as FinalField

Where PurgeChar(SubField(NewField, '|,', 2), ',|') = 881;

LOAD SubField(Field, ',|,') as NewField;

LOAD * Inline [

Field

08000355058|,803,|, National|,860,|, D1524|,881,|, M1529|,881,|, M1530|,881,|, M1531|,881,|

] (delimiter is @);


Capture.PNG

View solution in original post

8 Replies
sunny_talwar

Not really sure I understand what you are trying to do. Is your data coming from text file like a string? and you just want to extract this alpha-numeric code where it is followed by |,881?

Clever_Anjos
Employee
Employee

Please post your script here

richard_chilvers
Specialist
Specialist
Author

Sorry it is quite hard to explain. But you are correct. Whenever there is an alphanumeric code between a comma and '|,881' I wish to extract it.

sunny_talwar

May be this:

Table:

LOAD Trim(SubField(NewField, '|,', 1)) as FinalField

Where PurgeChar(SubField(NewField, '|,', 2), ',|') = 881;

LOAD SubField(Field, ',|,') as NewField;

LOAD * Inline [

Field

08000355058|,803,|, National|,860,|, D1524|,881,|, M1529|,881,|, M1530|,881,|, M1531|,881,|

] (delimiter is @);


Capture.PNG

JonnyPoole
Employee
Employee

load

  Code,

  Identifier

where Identifier='881';

load

  subfield(Row,'|',1) as Code,

  SubField(Row,'|,',2) as Identifier;

load

  SubField(Data & ',',',|,') as Row;

load * inline [

Data

08000355058|,803,|, National|,860,|, D1524|,881,|, M1529|,881,|, M1530|,881,|, M1531|,881,|

] (delimiter is ':') ;

sinanozdemir
Specialist III
Specialist III

It seems like you also want to pull the codes from the left side of the first 881. I believe you also don't want to hard code the numbers in Subfield() so you can use IterNo() with it.

Capture.PNG

Here is the data model:

Capture.PNG

Hope this helps.

richard_chilvers
Specialist
Specialist
Author

Thanks - that's neat !

richard_chilvers
Specialist
Specialist
Author

Thanks everyone for taking the time to look.

All suggestions seem to do the trick !