Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
drminaker
Contributor III
Contributor III

Combing two functions in load script (trim and replace)

Hi,

I'm trying to clean up a field and need to apply two functions in the load script. I've read through several other discussion posts and just can't seem to get the right syntax for this to work.

These are the two functions that I'd like to combine (both work as expected on their own). Any help is much appreciated.

If(Len(Trim(Instructor_Name)) > 0, Instructor_Name, 'None Specified') as [Instructor name],     //Replaced blanks with text

Replace (Instructor_Name,'  ',' ') as [Instructor name],    //Removes extra spaces between instructor names

Thanks in advance!

R.

1 Solution

Accepted Solutions
sunny_talwar

May be this

If(Len(Trim(Instructor_Name)) > 0, Replace (Instructor_Name,'  ',' '), 'None Specified') as [Instructor name]

View solution in original post

7 Replies
sunny_talwar

May be this

If(Len(Trim(Instructor_Name)) > 0, Replace (Instructor_Name,'  ',' '), 'None Specified') as [Instructor name]

rubenmarin

Hi Ryan, you can use Trim to remove the extra spaces:

If(Len(Trim(Instructor_Name)) > 0, Trim(Instructor_Name), 'None Specified') as [Instructor name]

sunny_talwar

it seems that the OP is looking to making double space into single space.....but I might be wrong...

rubenmarin

It was just to give an idea, the comments says "Removes extra spaces between instructor names" but the code will only work if there are exactly two spaces, not three or more.

drminaker
Contributor III
Contributor III
Author

Sunny, thanks so much. I was trying to add the Replace before/after the Trim, not combining the two as you've done, which is obviously why I didn't work.

R.

drminaker
Contributor III
Contributor III
Author

Thanks Ruben! I was trying to remove cases where people's names had an accidental double space between first and last. My first attempt at solving this was with Trim, but realized I couldn't use it to remove extra spaces inside a string.

R.

rubenmarin

True, I don't know when I started to think that it removes spaces in the middle.