Solved Instring Looking for Space When Doesn't Exist

dgreen

Member
Local time
Yesterday, 23:59
Joined
Sep 30, 2018
Messages
397
I'm trying to pick up the person's first name (ie. "John" from "John Smith") but in some cases the fosUserName is only a single value (Owner).

How would you modify the code to recognize this?

Code:
Left(fOSUserName(), InStr(1, fOSUserName(), " ") - 1)
 
How to test if the string is just a single word?
 
Code:
IIF(InStr(1, Trim(fOSUserName()), " ") > 1,InStr(1, Trim(fOSUserName()), " ") - 1,fOSUserName() )
 
@Gasman Close enough to get me there. I'll test on my unique user. Thanks.

Code:
Zira.Speak "" & GetGreeting() & IIf(InStr(1, Trim(fOSUserName()), " ") > 1, Left(fOSUserName(), InStr(1, fOSUserName(), " ") - 1), fOSUserName())
 
An alternative to testing for the space is to concatenate a space to the end of the name so that it will always be present.
 

Users who are viewing this thread

Back
Top Bottom