Text Items should have two values but sometimes has one. How to test?

This seems somewhat basic but I have a person’s name attached to a scalar value.


set nameOfContact to extract name from sender of theMessage

in some cases, the name isn’t like “Donald Duck” but rather “Donald”.

My code has set the delimeter to a space.

My script fails because it expecting two values.

How can I test to see if text item 2 of the nameOfContact is null?

simply by counting because text item 2 doesn’t exists, it isn’t null if nameOfContact doesn’t contain a space

--when delimiters are set to space
if count text items of nameOfContact is 1 then
--there is no space in the name
else
--there is a space in the name
end

Well, I tried this but it counts each letter in the scalar. It’s as if it coerced the value to one string and the count is each individual value.

Not if you have you read correctly my comments in the code.

If you count text items when delemiter is set to “” (by default) it will count every character but if you set applescript’s text item delimiters to space it would count as you wished for

get the original string ad do this:

if offset of " " in originalName is 0 then
--only one 'word'
else
--one or more spaces detected.
end

hope this helps


if nameOfContact contains " " then
	-- donald duck
else
	-- donald
end if