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

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
jblomqvist
Specialist
Specialist

How to replace field values where there is lots of blank spaces between text with only single space?

Hi all,

How to replace field values where there is lots of blank spaces between text with only single space?

I have a Description field that contains values like this, see an example table:

 

DateDescription
10/12/2019Bank          America        344556
05/12/2019Legal&Fin      344556
02/12/2019Transfer                   Note           Confirm
02/12/2019

634465768 Telephone

 

As you can see in the example above the Description values have blank spaces between text, how can I replace many of them by just reducing the spaces to 1 space?

2 Replies
Frank_Hartmann
Master II
Master II

maybe like that:

 

keepchar(Description,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890 ')	 as  Description_New

 

Vegar
MVP
MVP

You can solve this by using a mapping table. Consider this script example:

 

 

/*Create a map table consising of multiple blanks as lookup value
single blank as replace value. Important to have the longest blank string first in the map table an the shortest  '  ' last in the map table.*/
map_blank:
mapping LOAD 
  repeat(' ', 100-IterNo()) as A,
  ' '
AutoGenerate 1
while IterNo() < 100;

/*Map the substings of Description using the map table above.*/
LOAD 
*, 
MapSubString('map_blank', Description) as Description_cleaned 
Inline [
Date	Description
10/12/2019	Bank          America        344556
05/12/2019	Legal&Fin      344556
02/12/2019	Transfer                   Note           Confirm
02/12/2019	634465768 Telephone
](delimiter is '	') 
;