0

I would like to remove all characters after the first white space instance.

My use case: In my table, I have a name column that is not separated into first and last. They are combined (e.g. 'John Doe' in one cell). I would like to delete everything after the first whitespace instance (e.g. 'John Doe' --> 'John').

Is that possible in AMPScript?

I saw the trim() function, but that does not seem to do what I want.

Thank you

1 Answer 1

3

What you need is a combination of IndexOf and SubString.

You would use IndexOf to find the first whitespace and then use substring to pull from first character up to the index of the whitespace.

Example:

%%[

    SET @Name = "John Doe"

    SET @Index = IndexOf(@Name, " ")

    SET @fName = SubString(@Name, 1, Subtract(@Index, 1))

]%%

**You subtract 1 from the index because the index includes the count of the white space character.

Keep in mind if the person has a two name first name, it will cut off the second part. E.g. "Jean Marie Jones" would just become "Jean" instead of "Jean Marie".

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .