Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
nigharikkha
Contributor II
Contributor II

Replace only the strict string

Hi all,

I am using Replace() in load script to replace certain substrings. However, I am facing the following difficulty.

Field values: 'PRE1','PRE2','PRE3','PRE4','PRE5','PRE6','PRE7','PRE8','PRE9','PRE10','PRE11','PRE12','PRE13','PRE14','PRE15'

I need the following replacements:

PRE1 --> PRE01

PRE2 --> PRE02..... and so on until PRE9 --> PRE09.

If I use replace function, the strings PRE10 and PRE20 are converted into PRE010 and PRE020.

Can you please help in this so that only the exact value are getting replaced and not substring?

Labels (1)
1 Solution

Accepted Solutions
marcus_sommer

You may use something like this:

purgechar(Field, '0123456789') & num(keepchar(Field, '0123456789'), '00') as Field

- Marcus

View solution in original post

3 Replies
James5654
Contributor II
Contributor II

The JavaScript String replace() method returns a new string with a substring ( substr ) replaced by a new one ( newSubstr ). Note that the replace() method doesn't change the original string. It returns a new string.

marcus_sommer

You may use something like this:

purgechar(Field, '0123456789') & num(keepchar(Field, '0123456789'), '00') as Field

- Marcus

nigharikkha
Contributor II
Contributor II
Author

Thanks @marcus_sommer . That is an intelligent way to handle. It works perfectly!!