community
cancel
Showing results for 
Search instead for 
Did you mean: 

Alteryx designer Discussions

Find answers, ask questions, and share expertise about Alteryx Designer.

Insert or add character into string at intervals

Meteor

Situation: Strings that are 4 characters long are getting concatenated into one sting in a single column due to insufficient controls during data input. For example: 'ABCDwxyz' should instead be split into 'ABCD' and 'wxyz' 

 

Sometimes 2 strings are concatenated, sometimes more. For example, 4 strings concatenated might look like this: 'ABCDwxyzLMNOefgh'

 

Using the following function (followed by a Text to Column tool, using a space as the delimiter) allows me to correct for this, but seems really crude:

 

IF 
[Site Len] = 8
THEN Substring([No 5th char],0, 4) + " " + Substring([No 5th char],4,4)

 

ELSEIF 
[Site Len] = 12
THEN Substring([No 5th char],0, 4) + " " + Substring([No 5th char],4,4) + " " + Substring([No 5th char],8,4)

 

ELSEIF 
[Site Len] = 16
THEN Substring([No 5th char],0, 4) + " " + Substring([No 5th char],4,4) + " " + Substring([No 5th char],8,4) + " " + Substring([No 5th char],12,4)

 

ELSE 'Error'

ENDIF

 

 

 

I imagine there's a more elegant solution out there. Any ideas? 

 

Here's a depiction of the input and desired output: 

InputOutput1Output2Output3Output4
ABCDABCD   
ABCDwxyzABCDwxyz  
ABCDwxyzLMNOefghABCDwxyzLMNOefgh
Alteryx Partner

Hi @Bobe,

 

Could you provide an example of the input data and desired output?  That would go a long way in helping the community help you with optimizing this workflow.

 

jm

Meteor

@john_miller9 Certainly. I've added a mock up to the bottom of the original post. Hopefully that helps illustrate the concept. 

Alteryx
Alteryx

If it's 4 characters each time then Regex Tokenize with the Expression '(.{4})' will get you what you want.

Asteroid

Try this: (In reg exp, you can also write .{4})

String.JPG

Labels