M
mallard134
Could someone please help a newbee vb programmer with a question that
is driving me crazy. I am trying to understand a line of code that is
supposed to return the domain portion of a valid email address. The
following code works!
******************************************************************
strEmail = "(e-mail address removed)"
String2 = strEmail.Substring(strEmail.IndexOf("@") + 1, _
strEmail.IndexOf(".", strEmail.IndexOf("@") + 1) _
- strEmail.IndexOf("@") - 1)
******************************************************************
String2 will contain the string "mydomain" . I understand the IndexOf(
) method
will return a zero based index of the char your searching for and that
the method
string.Substring( ) returns a substring of a string using start and
size arguments,
ie: Substring( start, size) but if you look at the email above the
start position would be the
index of 5 or the 'm' in mydomain. the num chars would be 13 - 3 = 10
chars. So if you
start at the 5th char and return 10 char's I would think that you would
return the string
"mydomain.c". Now to really get things confusing I did a little test
in the following code.
I broke up the different index search's only I took the index of the
period + 1 and subtracted
the position of the '@' sign + 1 which made more sense to me and I got
8 char's, then I used that value in the substring( ) procedure and I
get the correct answer. My confusion is how can both way's work?
Obviously I am really confused on this, if anyone could help with the
explanation I would really appreciate it.
Thanks
Scooby
**************************************************************
Dim strEmail As String
Dim var1 As Integer
Dim var2 As Integer
Dim var3 As Integer
Dim String1 As String
Dim String2 As String
strEmail = "(e-mail address removed)"
var1 = strEmail.IndexOf("@") + 1
var2 = strEmail.IndexOf(".", strEmail.IndexOf("@") + 1)
var3 = var2 - var1
String1 = strEmail.Substring(strEmail.IndexOf("@") + 1, var3)
String2 = strEmail.Substring(strEmail.IndexOf("@") + 1, _
strEmail.IndexOf(".", strEmail.IndexOf("@") + 1) _
- strEmail.IndexOf("@") - 1)
Both String1 and String2 will = "mydomain"?
is driving me crazy. I am trying to understand a line of code that is
supposed to return the domain portion of a valid email address. The
following code works!
******************************************************************
strEmail = "(e-mail address removed)"
String2 = strEmail.Substring(strEmail.IndexOf("@") + 1, _
strEmail.IndexOf(".", strEmail.IndexOf("@") + 1) _
- strEmail.IndexOf("@") - 1)
******************************************************************
String2 will contain the string "mydomain" . I understand the IndexOf(
) method
will return a zero based index of the char your searching for and that
the method
string.Substring( ) returns a substring of a string using start and
size arguments,
ie: Substring( start, size) but if you look at the email above the
start position would be the
index of 5 or the 'm' in mydomain. the num chars would be 13 - 3 = 10
chars. So if you
start at the 5th char and return 10 char's I would think that you would
return the string
"mydomain.c". Now to really get things confusing I did a little test
in the following code.
I broke up the different index search's only I took the index of the
period + 1 and subtracted
the position of the '@' sign + 1 which made more sense to me and I got
8 char's, then I used that value in the substring( ) procedure and I
get the correct answer. My confusion is how can both way's work?
Obviously I am really confused on this, if anyone could help with the
explanation I would really appreciate it.
Thanks
Scooby
**************************************************************
Dim strEmail As String
Dim var1 As Integer
Dim var2 As Integer
Dim var3 As Integer
Dim String1 As String
Dim String2 As String
strEmail = "(e-mail address removed)"
var1 = strEmail.IndexOf("@") + 1
var2 = strEmail.IndexOf(".", strEmail.IndexOf("@") + 1)
var3 = var2 - var1
String1 = strEmail.Substring(strEmail.IndexOf("@") + 1, var3)
String2 = strEmail.Substring(strEmail.IndexOf("@") + 1, _
strEmail.IndexOf(".", strEmail.IndexOf("@") + 1) _
- strEmail.IndexOf("@") - 1)
Both String1 and String2 will = "mydomain"?