Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
kschramm
Partner - Contributor II
Partner - Contributor II

Stripping lead char's within an If statement

This should be simple for anyone who has done this before.

I have an 8 char code (UCODE) that if the first position is a "P", I want to strip the P from the code and keep the remaining char's and move everything to the left one space.  Can someone provide the syntax for that?  I have tried many examples and cannot get any to work  Thank you in advance.

1 Solution

Accepted Solutions
Ralf-Narfeldt
Employee
Employee

I think the definite reference is the Qlik Help section describing functions:

http://help.qlik.com/sense/2.0/en-US/online/#../Subsystems/Hub/Content/Scripting/functions-in-script...

I can explain my example:

left(UCODE,1) = The first character in UCODE from the left.


PurgeChar(left(UCODE,1),'P') = Return a string consisting of he first character in UCODE from the left with 'P' purged. So if it's a P an empty string is returned, otherwise the first letter of UCODE.


mid(UCODE,2) = The string UCODE starting from the second character until the end.

The & concatenates the two strings

PurgeChar(left(UCODE,1),'P')&mid(UCODE,2)


If you were positive that UCODE could only contain a P in the first position it would be even simpler. Then PurgeChar(UCODE, 'P') would be fine.

View solution in original post

9 Replies
lironbaram
Partner - Master III
Partner - Master III

hi

you cna try

=if(left(UCODE,1)='P',right(UCODE,7),UCODE)

tresesco
MVP
MVP

If(Left(UCODE,1)='P', mid(UCODE,2), UCODE)

Kushal_Chawda

try,

load *,

if(left(UCODE,1)='P', purgechar(UCODE,'P'),UCODE) as UCODE

From Table

Not applicable

Hi,

Try this

if(left(UCODE,1)='P',TRIM(MID(UCODE,2,LEN(UCODE))),UCODE)

Ralf-Narfeldt
Employee
Employee

Many ways to get what you want. One without an if:

PurgeChar(left(UCODE,1),'P')&mid(UCODE,2)

kschramm
Partner - Contributor II
Partner - Contributor II
Author

Thanks to all.    Since I am a newbie, the biggest challenge that I face is reference material that describes each function and what the keywords mean.  I go back and forth between the Qlik Help and the reference manual and don't know what "MID" means in this example (just an example)

if(left(UCODE,1)='P',TRIM(MID(UCODE,2,LEN(UCODE))),UCODE)

You have probably faced this before so if anyone has suggestions on the best function syntax/keyword document I am all ears.  I use the Qlik community as well but most of the examples are similar to what I am looking for but not exact.  Thank you again for any assistance.

Ralf-Narfeldt
Employee
Employee

I think the definite reference is the Qlik Help section describing functions:

http://help.qlik.com/sense/2.0/en-US/online/#../Subsystems/Hub/Content/Scripting/functions-in-script...

I can explain my example:

left(UCODE,1) = The first character in UCODE from the left.


PurgeChar(left(UCODE,1),'P') = Return a string consisting of he first character in UCODE from the left with 'P' purged. So if it's a P an empty string is returned, otherwise the first letter of UCODE.


mid(UCODE,2) = The string UCODE starting from the second character until the end.

The & concatenates the two strings

PurgeChar(left(UCODE,1),'P')&mid(UCODE,2)


If you were positive that UCODE could only contain a P in the first position it would be even simpler. Then PurgeChar(UCODE, 'P') would be fine.

Not applicable

Hi,

You can try this:

=if(left(vMyName,1)='P', right(vMyName,len(vMyName)-1),vMyName)

MarcoWedel

Hi,

another solution could be:

Mid(UCODE,1-(UCODE like 'P*'))

QlikCommunity_Thread_172267_Pic1.JPG

LOAD *,

     Mid(UCODE,1-(UCODE like 'P*')) as UCODE2

INLINE [

    UCODE

    P1234567

    12345678

    A3456789

    B4567890

    98765432

    P56789012

    PDSFGSDF

    DFGDGSDFGD

    PEWRTWET   

];

hope this helps

regards

Marco