Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

How to take out blank spaces within a string

wenjuanchen
8 - Asteroid

Hello everyone,

 

I want to delete blank spaces within a string. For example, I want to take out blank spaces in the following string:  "A & B" and get "A&B".

 

Can anyone help? Thank you so much!

7 REPLIES 7
jrgo
14 - Magnetar

@wenjuanchen

 

Take your pick...

 

ReplaceChar([text],’ ‘,’’)

 

Regex_Replace([text],’\s’,’’)

wenjuanchen
8 - Asteroid
Thank you so much!
BogdanCalacean
7 - Meteor

Great answer. What if there was "10 A & B" and would like to see "10 A&B"?

jrgo
14 - Magnetar

@BogdanCalacean 

 

REGEX_REPLACE([Text], '\s?(&)\s?', '$1')

This would work to remove spaces found before and/or after the marked group, which is only the "&" char, and replacing that found matches with the marked group, which is the $1 in the 3rd param. If it's required that a space be found before and after, remove the ?.

Jimmy
Teknion Data Solutions

EricaNHenk
6 - Meteoroid

Good afternoon!

 

I am trying to figure out the correct formula to remove the extra space in the full name. I have a screenshot of what the name looks like before, and the second screenshot is how I want my end result to look. Any advice is greatly appreciated!

 

Lorianne Spurr
LorianneSpurr

 

 

Thanks,

 

Erica

jrgo
14 - Magnetar

Hi @EricaNHenk 

 

Not sure I fully understand your need. You mention that you want to remove extra space, which I would have interpreted as replacing 2 or more consecutive spaces with a single space, but the screenshots you shared suggest that you want to remove ALL spaces from the text string, in which case, the solution on this post should satisfy that need.

 

If it's not working, can you describe what you're seeing when the suggested expressions are attempted?

JTSJr
5 - Atom

This does not work for me.

Labels