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: 
quilldew
Creator
Creator

Remove characters at start of string

Hi all,

I know this is a popular one, and I've read many threads about string functions but I can't seem to put one together to fit this particular need.

I wish to remove any character before a name. This name is preceded by numbers and spaces and a hyphen, and sometimes another separator (usually a dot). Examples are:

1 - Name

12 - Name

23 -  Name

3.1 - Name

2- Name

2-Name

Name

2.5 - Name - SecondPartofName

I've tried various combinations of Trim(), Mid(), Left(), PurgeChar() but don't seem to be able to just keep the name.

I've considered using if()'s but I'm trying to keep the script fast as I'll be using this on lots of imported fields.

Any ideas?

Many thanks.

1 Solution

Accepted Solutions
sunny_talwar

Sample script

Table:

LOAD *,

Trim(Mid(FieldName, Index(FieldName, '-') + 1)) as Name;

LOAD * INLINE [

    FieldName

    1 - Name

    12 - Name

    23 -  Name

    3.1 - Name

    2- Name

    2-Name

    Name

    2.5 - Name - SecondPartofName

];

Which give me this

Capture.PNG

View solution in original post

6 Replies
PrashantSangle

use trim(subfield(fieldName,'-',2))

Regards

Great dreamer's dreams never fulfilled, they are always transcended.
Please appreciate our Qlik community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂
stigchel
Partner - Master
Partner - Master

Try with

Trim(SubField(YourField,'-',2)) as Name

quilldew
Creator
Creator
Author

Thanks for the suggestion,

Unfortunately the Name sometimes also has a hyphen within the name. This gets rid of everything after the second hyphen too.

sunny_talwar

May be this

Trim(Mid(FieldName, Index(FieldName, '-') + 1)) as Name

sunny_talwar

Sample script

Table:

LOAD *,

Trim(Mid(FieldName, Index(FieldName, '-') + 1)) as Name;

LOAD * INLINE [

    FieldName

    1 - Name

    12 - Name

    23 -  Name

    3.1 - Name

    2- Name

    2-Name

    Name

    2.5 - Name - SecondPartofName

];

Which give me this

Capture.PNG

quilldew
Creator
Creator
Author

Sunny!

I wondered how long it would take you

Thank you very much again that worked perfectly.