Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Esneider
Partner - Contributor III
Partner - Contributor III

Delete Space in Data

Hi,

In one of my fields, I have data like '    XXXX   YYY   ZZ' and I want them as 'XXXX YYY ZZ'

How can I do that?

1 Solution

Accepted Solutions
Anonymous
Not applicable

This is an example of Rob Wunderlich's technique, check CLEANED_TEXT after cleaning from spaces.

SpaceMap:

MAPPING LOAD repeat(' ', RecNo()), ' '
AutoGenerate 10  // up to 10 spaces
;

SAMPLE:
LOAD * Inline
[TEXT
HELLO AND            WELCOME
THIS IS A SAMPLE TEST
I       AM NOT SURE
]
;

DATA2:
LOAD MapSubString('SpaceMap', trim(TEXT)) as CLEANED_TEXT
Resident SAMPLE;

I hope this helps!

MultiView
 

View solution in original post

14 Replies
Not applicable

While loading your data in script editor, You can use ltrim() function to remove leading spaces.

example: 

from xyz.......

similary rtrim() to remove spaces from the end.

Below will remove leading and trail spaces from column name Relation and alias name of that column will be rel

ltrim(rtrim(Relation)) as rel 

 

LOAD

ltrim(Relation) as rel

Not applicable

While loading your data in script editor, You can use ltrim() function to remove leading spaces.

example: 

 

 

LOAD

  ltrim(Relation) as rel

 

 

from xyz.......

similary rtrim() to remove spaces from the end.

Below will remove leading and trail spaces from column name Relation and alias name of that column will be rel

ltrim(rtrim(Relation)) as rel 

sujeetsingh
Master III
Master III

If the trend is constant then we can do it.

let the field be Name

expression can be like this

=Subfield(Name,'  ')

may it work

sivarajs
Specialist II
Specialist II

This might helps you

Replace(LTrim('   XXXX   YYY   ZZ'),'  ',' ')

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

One solution would be to use a MAPPING TABLE wih MapSubstring().

SpaceMap:

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

AutoGenerate 10  // up to 10 spaces

;

And in your LOAD statement:

MapSubString('SpaceMap', trim(x)) as y

-Rob

Anonymous
Not applicable

That's an excellent solution!

Regards

MultiView

sujeetsingh
Master III
Master III

Rob ,

will you please explain how it works

?

Esneider
Partner - Contributor III
Partner - Contributor III
Author

Hi Rob,

Please can you send a example in qvw?

Thanks,

Esneider
Partner - Contributor III
Partner - Contributor III
Author

Hi,

You have the example in qvw?