MailAddress和unicode字符 [英] MailAddress and unicode characters

查看:96
本文介绍了MailAddress和unicode字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MailAddress在地址字段中引发带有Unicode字符的FormatException +看起来您可以在构造函数中指定的编码是用于显示名称的.这是设计使然吗?推荐的处理Unicode字符的方法是什么 在电子邮件地址中?

MailAddress is throwing a FormatException with Unicode characters in the address field + looks like the encoding you can specify in the constructor is for the display name. Is this by design? What is the recommended way of handling unicode characters in the email address?

尝试
{
    MailAddress a = new MailAddress("リンク@ blah.com);
}
catch(异常e)
{
   有效=假;
}

try
{
    MailAddress a = new MailAddress("リンク@blah.com");
}
catch (Exception e)
{
    valid = false;
}

推荐答案

使用下面的构造函数

Use the constructor below

public MailAddress(string address, string displayName, Encoding displayNameEncoding);


MailAddress a = new MailAddress("リンク@blah.com","myname",Encoding.Unicode);



这篇关于MailAddress和unicode字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆