Unicode encoding in code editor?

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,818
Location
Norway
Programming Experience
10+
I was just testing some email code today and encountered the strangest problem. Specifically I was initializing a Net.Mail.MailAddress with an address string I copied from some 'foreign' :eek: email application, code like this:
VB.NET:
Dim m As New Net.Mail.MailAddress("a@b.c")
No matter what I got this:
System.FormatException was unhandled
Message="The specified string is not in the form required for an e-mail address."
Source="System"
StackTrace:
at System.Net.Mime.MailBnfHelper.ReadMailAddress(String data, Int32& offset, String& displayName)
...
editing the address in code editor gave same result, but when I typed the exact same string in a new code line it executed fine. There are no observable strange characters in the string. It was also not a glitch, I reproduced it several times, also including restarting IDE.

The only explanation I can think of is that the string is differently encoded, but I thought the encoding used in code editor was Unicode (Utf-8), and that text pasted from differently encoded strings would either be converted or appear differently in editor? Any ideas about this?
 
I finally got around to analyzing the ascii bytes of that string and it contained character 30 at start of string, this is a non-printable character called "Record Separator", it was used as data separator in serial storage in the sixties, and is not a valid char in email address. A weird thing to find in a textbox in a modern application, but a simple explanation to the problem.
 
Back
Top