I have a DE which has Full names in it. I wanted to extract the first name from it, so I wrote the following ampscript:
%%[
var @fullName
var @firstName
set @fullName = AttributeValue("fullName")
if indexOf(@fullName, " ") > 0 then
set @firstName = Substring(@fullName,1, Subtract(IndexOf(@fullName," "),1))
endif
]%%
%%=v(@firstName)=%%
This worked! If the Full Name was "Mouse Keyboard", then it would only display "Mouse". However, I realised some people have only written their 'First Name' in 'Full Name'.. So with the above ampscript, if someone has written simply 'Mouse' under Full Name, it won't display anything, it'll be left blank.
I can't figure how to edit the above ampscript to do two things at once:
- Separate first name from 'Full Name' [which I've done]
- But, if there's only the first name (one word) under 'Full Name', then simply display that