Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
settu_periasamy
Master III
Master III

Replace with String Contains

Hi,

I need to replace the string based on between the values(like textbetween). see the example below.

Need to replace the String ': * |' as blank. (note :  '*' contains any length)

FieldOne: raja | FieldTwo: India | FieldThree: Calculated |

result should be :

FieldOne FieldTwo FieldThree

i tried the below expression

'=replace('FieldOne: raja | FieldTwo: India | FieldThree: Calculated |',':'&chr(42)&'|',' ')

Thank You.

1 Solution

Accepted Solutions
jagan
Partner - Champion III
Partner - Champion III

Hi Sethu,

Copy the string into a variable and use that variable in the expression.  If your string is dynamic like 4, 5 , 6 values then trying this in script is the best option.

Regards,

Jagan.

View solution in original post

12 Replies
ToniKautto
Employee
Employee

That's gonna be hard in a sheet object. I would suggest doing it in the script, so your data is pre-formatted for presentation.

LOAD

  SubField(F1, ':', 1) AS F1

;

LOAD

  SubField(F1, ' | ')  AS F1

Inline [

F1

FieldOne: raja | FieldTwo: India | FieldThree: Calculated |

];

senpradip007
Specialist III
Specialist III

Try with

=PurgeChar('FieldOne: raja | FieldTwo: India | FieldThree: Calculated |', ':|')

danieloberbilli
Specialist II
Specialist II

LOAD *,

left(F1, Index(F1,':',1)-1) &' '&

    mid(F1,Index(F1,'|',1)+1,Index(F1,':',2)-Index(F1,'|',1)-1 ) &' '&

    mid(F1,Index(F1,'|',2)+1,Index(F1,':',3)-Index(F1,'|',2)-1 ) as Result

;

LOAD * INLINE [

    F1

    FieldOne: raja | FieldTwo: India | FieldThree: Calculated |

];

jagan
Partner - Champion III
Partner - Champion III

Hi,

Try like this in script

Temp:

LOAD

  RecordNum, 

  RowNo() AS Num,

  SubField(F1, ':', 1) AS F1 

LOAD RecNo() AS RecordNum, 

  SubField(F1, ' | ')  AS F1 

Inline [ 

F1 

FieldOne: raja | FieldTwo: India | FieldThree: Calculated | 

];

Data:

LOAD

RecordNum,

CONCAT(F1, ' ', Num) AS Value

RESIDENT Temp

GROUP BY RecordNum

ORDER BY Num;

DROP TABLE Temp;

OR if you want to do it in front end try like this

=SubField(SubField('FieldOne: raja | FieldTwo: India | FieldThree: Calculated |', ' |', 1), ':', 1) & ' ' & SubField(SubField('FieldOne: raja | FieldTwo: India | FieldThree: Calculated |', ' |', 2), ':', 1) &

SubField(SubField('FieldOne: raja | FieldTwo: India | FieldThree: Calculated |', ' |', 3), ':', 1)

Hope this helps you.

Regards,

Jagan.

settu_periasamy
Master III
Master III
Author

Thanks Jagan.

I want to do this in front end.  The given expression is fine.

But if I have Large String,  is any other function is available?

Regards,

Sethu

settu_periasamy
Master III
Master III
Author

Hi,

I tried this. But not getting the expected result.

ToniKautto
Employee
Employee

I assume the long string comes from the loaded data, so why do you want to process it in run-time instead of pre-processing it during reload?

I realized I forgot to add the concat in my example.

LOAD Concat(F1) AS F1;

LOAD SubField(F1, ':', 1) AS F1;

LOAD SubField(F1, ' | ')  AS F1

Inline [

F1

FieldOne: raja | FieldTwo: India | FieldThree: Calculated |

];

danieloberbilli
Specialist II
Specialist II

My example from above also works in the frontend...just type the following expression in a textbox or chart and replace the field name

left(F1, Index(F1,':',1)-1) &' '&

    mid(F1,Index(F1,'|',1)+1,Index(F1,':',2)-Index(F1,'|',1)-1 ) &' '&

    mid(F1,Index(F1,'|',2)+1,Index(F1,':',3)-Index(F1,'|',2)-1 )

settu_periasamy
Master III
Master III
Author

Thanks Toni. I will try to implement this in the script.