VB expression to rearrange a string in the right format for example variable is in "SecondName, FirstName" and need to change this to show as "FirstName SecondName"

I’m stuck trying to find the right VB expression to rearrange a string in the right format for example variable is in “SecondName, FirstName” and need to change this to show as “FirstName SecondName”. Any suggestions what is the suitable expression??

Hi,

You can do it using Replace activity with the following settings.

Pattern : "^(\w+),\s*(\w+)$"
Replacement : "$2 $1"

Regards,

Ah okay that’s great thanks. What if there was a middle letter like the X in the middle as there could be a letter in the middle in the odd time - “SecondName, X FirstName”. I’m guessing that this wouldn’t output in the right way?

Hi,

What if there was a middle letter

Can you try the following?

Pattern: "^(\w+),(\s*\w*\s+)(\w+)$"
Replacement: "$3$2$1"

The result will be “FirstName X SecondName”. Does this fit for you?

Regards,

Yes that would help alot. Thanks a million :slight_smile:

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.