Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
mlarruda
Creator II
Creator II

How can I delete specific characters from a string variable?

Hi, I have a variable/column called NAME, where some names start with "Dr ", Mr" etc. and I want to delete this to make "Mr. James" become only "James", for example.

I did this subroutine:

SUB CleanName (SourceString)

IF Left(SourceString,3) = 'Mr '

SourceString = Right(SourceString,Len(SourceString)-3);

IF Left(SourceString,3) = 'Ms '

SourceString = Right(SourceString,Len(SourceString)-3);

IF Left(SourceString,4) = 'Mrs '

SourceString = Right(SourceString,Len(SourceString)-4);

IF Left(SourceString,3) = 'Dr '

SourceString = Right(SourceString,Len(SourceString)-3);

END SUB

And called it by typing

CALL CleanName(NAME);

in the last row of the Main tab, nut it didn't work.

Any friend can point me where is the error or how can I do what I want?

11 Replies
mlarruda
Creator II
Creator II
Author

Thanks but didn't work.

mlarruda
Creator II
Creator II
Author

Merging some suggestions, I found the solution:

if(match(subfield($1,' ',1),'Mr','Ms','Mrs','Dr'),trim(replace($1,subfield($1,' ',1),' ')),$1)

Thank very much for all!