
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Replace one character in string
Hi,
I'd like to write an expression where if the fourth character of a string is '1', it is replaced with a 'P'. I'm able to replace the character and keep the expression before the fourth character, but am having trouble keeping the latter half of the string because if there is another '1' later in the string, the subfield portion of the expression picks those up as well. How to get the rest of the text after a certain character? I'm sure there are better ways to accomplish what I wrote. Any improvements are also greatly appreciated. Thank you!
This is the expression I used and I'm trying to fill in the blank space. I used the subfield expression below to fill in the space but it is not functioning correctly.
=if(mid([Animal Name], 4,1) = '1', left([Animal Name], 3)&replace(mid([Animal Name], 4,1), '1', 'P'&_______), [Animal Name])
=subfield([Animal Name], mid([Animal Name], 4, 1), -1)
Animal Name |
Desired Output |
CHI1ABFBW |
CHIPABFBW |
COWLABFBW |
COWLABFBW |
PIG12351 |
PIGP2351 |
SH11IO1BB |
SH1PIO1BB |
A111WBI154 |
A11PWBI154 |
Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think this should do the trick:
=if(mid([Animal Name], 4, 1) = '1',
left([Animal Name], 3) & 'P' & right([Animal Name], len([Animal Name])-4),
[Animal Name])
Also replied on other duplicate post:
https://community.qlik.com/t5/QlikView-App-Dev/Replace-part-of-String/td-p/1995723

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think this should do the trick:
=if(mid([Animal Name], 4, 1) = '1',
left([Animal Name], 3) & 'P' & right([Animal Name], len([Animal Name])-4),
[Animal Name])
Also replied on other duplicate post:
https://community.qlik.com/t5/QlikView-App-Dev/Replace-part-of-String/td-p/1995723

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you Nicole, this worked perfectly!
