URL Encode all non alpha numeric in C#

后端 未结 4 1381
轻奢々
轻奢々 2021-01-12 11:01

I need to fully URL Encode an email address.

HttpUtility.UrlEncode seems to ignore certain characters such as ! and .

I need to pass an email address in a ur

4条回答
  •  爱一瞬间的悲伤
    2021-01-12 11:29

    Here's a potential Regex you could use to accomplish the encoding.

    Regex.Replace(s, @"[^\w]", m => "%" + ((int)m.Value[0]).ToString("X2"));

    I'm not sure that there is an existing framework method defined to strictly encode all non-alphanumeric characters that you could point your clients to.

提交回复
热议问题