TrimEnd doesn't work with email address

  • Thread starter Thread starter ezra88
  • Start date Start date
E

ezra88

I'm trying t use these lines below to get "new string = "someone", but
it won't work. Instead it just keeps coming back as
"(e-mail address removed)". Is there something weird about there being an "@"
character or a "." character?

'Dim MyString As String = "(e-mail address removed)"
'Dim MyChar As Char() = {"."c, "@"c}
'Dim NewString As String = MyString.TrimEnd(MyChar)
'lblHolder.Text = NewString

Thanks,
Ezra
 
I think you have misunderstood how the TrimEnd methods works
You're telling it to remove all "." and "@" from the *end* of the string.
Since your string doesn't have any of those in the end, you'll simply
get the input string back. If you were to pass (e-mail address removed)@@@....
you would get (e-mail address removed) back

Use this instead:
Dim NewString As String = MyString.Split("@"c)(0)

/claes
 
Ezra,
In addition to using Split. I would consider using String.SubString along
with String.IndexOf or String.LastIndexOf, something like:

Dim MyString As String = "(e-mail address removed)"
Dim MyChar As Char() = {"."c, "@"c}
Dim NewString As String
If MyString.IndexOfAny(MyChar) <> -1 Then
NewString = MyString.Substring(0,
MyString.LastIndexOfAny(MyChar))
End If

I would use IndexOfAny if I wanted to split at the first occurrence and
LastIndexOfAny if I wanted to split at the last occurrence.

FWIW: Consider what happens in the above with addresses such as
(e-mail address removed), I know of a couple of Lotus Notes sites that use
(e-mail address removed) for their email addresses...

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| I'm trying t use these lines below to get "new string = "someone", but
| it won't work. Instead it just keeps coming back as
| "(e-mail address removed)". Is there something weird about there being an "@"
| character or a "." character?
|
| 'Dim MyString As String = "(e-mail address removed)"
| 'Dim MyChar As Char() = {"."c, "@"c}
| 'Dim NewString As String = MyString.TrimEnd(MyChar)
| 'lblHolder.Text = NewString
|
| Thanks,
| Ezra
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top