Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
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

1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

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)

View solution in original post

10 Replies
whiteline
Master II
Master II

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

Not applicable
Author

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

Anonymous
Not applicable
Author

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
Author

Michael,

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

Thanks,

Ralph

Anonymous
Not applicable
Author

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
Author

Yes that works brilliant. Many thanks,

Ralph

Not applicable
Author

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

Anonymous
Not applicable
Author

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
Author

Works great, thanks again.