开发者

VB6 Index of Substring

I'm trying to match domain names in email address开发者_如何学C strings in VB6 and it's not my everyday language. I basically want to extract the domain name from an address (i.e., admin@foo.com) for comparison. I would like to extract it by getting everything after "@" and I think finding the index of "@" and then using Left$() would satisfy my needs. How can I get the index?


You can use the InStr function to do this:

Example:

s$ = "admin@foo.com"
d$ = Mid$(s$, InStr(1, s$, "@") + 1)

The variable d$ would end up with the string "foo.com". (Don't forget to check to make sure that the @ sign is present, otherwise you would just end up with the whole source string.)


I'd use the Split function here.

Dim strEmail, arr, strDomain
strEmail = "emailaddress@website.com"
arr = Split(strEmail, "@")
if arr.Count > 1 then
    strDomain = arr(1)
end if

Hope this helps.

Edit
Sorry forgot to add a check that the array has more than 1 value.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜