In case you missed the announcement: The Alteryx One Fall Release is here! Learn more about the new features and capabilities here
ACT NOW: The Alteryx team will be retiring support for Community account recovery and Community email-change requests after December 31, 2025. Set up your security questions now so you can recover your account anytime, just log out and back in to get started. Learn more here
Start Free Trial

Alteryx Designer Desktop Discussions

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

Adding white space after specific characters

jenner85
8 - Asteroid

Hi - I would like to add a space, but only if the string begins with specific characters "TD"

 

BUSINESS CASH BACK - 0017

TDCASH BACK - 0001

TDAE PLATINUM - 0010

TDREWARDS - 0014

BUSINESS TRAVEL - 0007

 

Would like it to be:

BUSINESS CASH BACK

TD CASH BACK

TD AE PLATINUM

TD REWARDS

BUSINESS TRAVEL

 

I know how to remove the numbers and punctuation, just not sure how to space the TD.

thanks! 

2 REPLIES 2
jdunkerley79
ACE Emeritus
ACE Emeritus

Two options both using a formula tool:

 

Plain method:

 

IIF(StartsWith([Field1], "TD") AND Substring([Field1],2,1) != " ",
    "TD " +Substring([Field1],2),
    [Field1])

 

 

or you can do REGEX:

 

REGEX_REPLACE([Field1],"^TD(\S)", "TD $1")

 

 

Quick sample attached

Kenda
16 - Nebula
16 - Nebula

Hi @jenner85 

 

I would recommend utilizing the substring function in this case.

 

In a formula tool, I would use this expression:

iif(Substring([Field1],0,2)="TD", "TD " + Substring([Field1],2), [Field1])

 

Basically, this checks the first two characters of your string. If they're equal to "TD", then it adds a space and continues with the rest of the string. Otherwise, it keeps the original value.

 

Hope this helps! 

Labels
Top Solution Authors