Encode string in utf8

How to easily encode a string in utf8 using .NET (VB or C #)? For example, I need to encode a string like "This (is) my string", the result should be the string "This +% 28is% 29 + my + string".

TIA

In JP

0
source share
2 answers

This is a URL encoding, not a UTF8 encoding. Try this method:

HttpUtility.UrlEncode(value) 
+7
source

It looks like you need to encode the URL, not "encoding in UTF-8."

To do this, use

 string encodedString = System.Web.HttpUtility.UrlEncode(yourString) 

(UTF-8 is a mechanism for representing Unicode characters inside, and not for replacing characters that otherwise make sense when used in a URI.)

+1
source

Source: https://habr.com/ru/post/1382764/


All Articles