Qlik Community

QlikView Documents

Documents for QlikView related information.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.

Remove blank spaces between a string

MVP
MVP

Remove blank spaces between a string

The below code snippet helps in trims the blank spaces in the text.  Where as LTrim() and RTrim() removes the blank spaces in Left and Right side of the text.  To remove the blank spaces between a string this code snippet is very useful.  The below snippet replaces upto 1 to 10 blank spaces to single space.  If your string has more than 10 then increase the value in AutoGenerate().

SpaceMap:

MAPPING LOAD repeat(' ', RecNo()), ' '

AutoGenerate 10  // up to 10 spaces

;

LOAD

MapSubString('SpaceMap', trim('      XXXX     YYY     ZZ')) as y

AutoGenerate 1;

Hope this helps others.

Regards,

Jagan.

Tags (3)
Labels (1)
Comments
MVP
MVP

Why not just using purgechar(<yourField>, ' ') ?

MVP
MVP

Hi Ralf,

This script helps in removing the unnecessary spaces in between the strings and maintain a single space in between the characters.

As Purgechar(<yourField>, ' ') removes all spaces in the string, but it won't allow to maintain a single space between the words.

Regards,

Jagan.

MVP
MVP

Ah, I see (confusing title). Btw. you don't need to replace one space by another. So I would start the mapping table with a double space. This should also speed up the MapSubstring.

Not applicable

Not completely foolproof; however this method works quite well

purgechar(replace(<yourField>,repeat(chr(32),2),'@'),'@')

Note: I used the '@' symbol because my text had none...but any other symbol will work.

pipuindia99
Contributor II

Yes Purgechar also removes space in between, but there are different methods to solve this...

Version history
Revision #:
1 of 1
Last update:
‎02-27-2013 07:38 AM
Updated by: