Prev: Ignoring Case
Next: Check if Application Installed
From: Dan on 4 Mar 2010 16:49 Hey all, I am returning an email address in a variable and would like to just return the portion to the left of the '@' sign. What is the best way to do this? I know how to do it if I had 'john(a)domain.com' but when it's in the objuser.email variable I'm finding it more difficult. Thanks for any help.
From: Evertjan. on 4 Mar 2010 18:35 Dan wrote on 04 mrt 2010 in microsoft.public.scripting.vbscript: > Hey all, > I am returning an email address in a variable Returning? A strig vasiable, i suppose. > and would like to just > return the portion to the left of the '@' sign. What is the best way > to do this? There is not "best ay" is any coding, that depends on subjective evaluation. > I know how to do it if I had 'john(a)domain.com' "had"? Do you mean?: myVar = "john(a)domain.com" myVar = left(myVar,instr(myVar,"@")-1) > but when it's in the > objuser.email variable I'm finding it more difficult. What is an objuser.email variable? Is dat a read/write variable? -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
From: LikeToCode on 4 Mar 2010 19:35 Well you could use the Split function or use the Len, Instr, & Right Functions. Assuming objUser = "your.user(a)domain.com" 'get the length intA = Len(objUser) 'find the first occurrence of the "@" and subtract 1 intB = InStr(objUser,"@") - 1 'use the Right function to return all of the characters up to and including the "@" MsgBox Right(objUser,intA - intB) OR 'Split the string but ensure there is only one occurrence of "@" str = Split(objUser,"@") 'str is now an zero based Array and with a standard email address it will have 2 'members. newStr = "@" & str(1) MsgBox newStr
From: Al Dunbar on 4 Mar 2010 23:25 "LikeToCode" <LikeToCode(a)discussions.microsoft.com> wrote in message news:B4473A92-2295-4A1D-8713-C4A0E739048F(a)microsoft.com... > Well you could use the Split function or use the Len, Instr, & Right > Functions. > Assuming objUser = "your.user(a)domain.com" Actually, I think what he means is that objUser is an object one of whose properties is called email, whose string value is an smtp address... > 'get the length > intA = Len(objUser) > 'find the first occurrence of the "@" and subtract 1 > intB = InStr(objUser,"@") - 1 > 'use the Right function to return all of the characters up to and > including > the "@" > MsgBox Right(objUser,intA - intB) > OR > 'Split the string but ensure there is only one occurrence of "@" > str = Split(objUser,"@") > 'str is now an zero based Array and with a standard email address it will > have 2 > 'members. > newStr = "@" & str(1) > MsgBox newStr I think the question presupposes objUser.email to be a valid smtp address, in which case there should be no concern about the number of "@" signs. In that case this should suffice: leftPart = split(objUser.email,"@")(0) msgbox leftpart If there is concern that the string might possibly not be a valid smtp address, this stirs up a hornet's nest of possible issues, including the validity of such candidates as: bob(a)jones@hotmail.com bob.jones@ @hotmail.com bob.jones(a)fakemail.com.net.org IMHO, none of these appears as valid as this: "bob.jones(a)hotmail.com". But is that a valid email address if there is no such mailbox? /Al
|
Pages: 1 Prev: Ignoring Case Next: Check if Application Installed |