Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements

Breathe easy -- you now have more time to plan your next steps with Qlik!
QlikView 11.2 Extended Support is now valid through December 31, 2020. Click here for more information.

Not applicable

String function in script

Hello,

I have hopefully a very straightforward question that I just can't resolved. I have a particular field that displays data in the format "John Test TT - RRR" etc. I want it to be simply displayed as "John Test" so require " TT - RRR" to be removed. I've tried a range of string functions but haven't been able to get the correct answer. Thanks in advance,

Ralph

Tags (1)
1 Solution

Accepted Solutions
mov
Esteemed Contributor III

Re: String function in script

Either put the whole thing inside trim() function - it removes leading and trainling spaces, or modify the expression a little by adding -1:

left('John Test TT - RRR', index('John Test TT - RRR', ' ', 2)-1)

10 Replies
whiteline
Honored Contributor II

Re: String function in script

Try SubField([your string], ' TT', 1)

Not applicable

Re: String function in script

Sorry I should have made clear that "TT" and "RRR" can be different values and the RRR value can change in length (usually 2, 3 or 4 characters). Thanks

mov
Esteemed Contributor III

Re: String function in script

Ralph,

That means the the question is about the rules.  Does it mean you need to remove the part of the string staring from the 2nd space?

Regards,

Michael

Not applicable

Re: String function in script

Michael,

Yes anything starting from the 2nd space should be purged from the string.

Thanks,

Ralph

mov
Esteemed Contributor III

Re: String function in script

Try this:

left('John Test TT - RRR', index('John Test TT - RRR', ' ', 2))

Edit: If the name can be more than two words (John Lesley Test), you can count spaces from the end, assuming there are three:

left(Field, index(Field, ' ', -3))

Not applicable

Re: String function in script

Yes that works brilliant. Many thanks,

Ralph

Not applicable

Re: String function in script

Sorry just noticed one further thing with the below, there is a space after the name, e.g. "John Test ", how can I make it simply "John Test" with no space after Test?

Thanks again,

Ralph

mov
Esteemed Contributor III

Re: String function in script

Either put the whole thing inside trim() function - it removes leading and trainling spaces, or modify the expression a little by adding -1:

left('John Test TT - RRR', index('John Test TT - RRR', ' ', 2)-1)

Not applicable

Re: String function in script

Works great, thanks again.