Solved Instring Looking for Space When Doesn't Exist (1 Viewer)

dgreen

Member
Local time
Today, 14:26
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)
 

Gasman

Enthusiastic Amateur
Local time
Today, 19:26
Joined
Sep 21, 2011
Messages
14,046
Test for Instr() first?
 

dgreen

Member
Local time
Today, 14:26
Joined
Sep 30, 2018
Messages
397
How to test if the string is just a single word?
 

Gasman

Enthusiastic Amateur
Local time
Today, 19:26
Joined
Sep 21, 2011
Messages
14,046
Code:
IIF(InStr(1, Trim(fOSUserName()), " ") > 1,InStr(1, Trim(fOSUserName()), " ") - 1,fOSUserName() )
 

dgreen

Member
Local time
Today, 14:26
Joined
Sep 30, 2018
Messages
397
@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())
 

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 06:26
Joined
Jan 20, 2009
Messages
12,849
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

Top Bottom