|
|
|
Some time you need funky code don't bother yourself by hard coding to every things when Microsoft give you facility. Simply add refreces of System.Web to your project then where you need Encoding write this line System.Web.HttpUtility.HtmlEncode()
Sample example |
Click here to copy the following block | string StringWantToEncode ="Hello buddies"; string EncodedString =System.Web.HttpUtility.HtmlEncode(System.Web.HttpUtility.HtmlEncode());
and Decoding is simple as Encoding only the function name is diffrent HttpUtility.HtmlDecode()
The code that I was using before knowing HttpUtility Class is below
private string ConvertToASCII(string val) { string[] split = val.Split(new char[] { StringBuilder sb =new StringBuilder(); string ReturnValue = ""; foreach (string st in split) { string st2 = st.Replace("&#", ""); if (st2 != String.Empty) {
int i = 0; int.TryParse(st2, out i); char ch = Convert.ToChar(i); sb.Append(ch); } } ReturnValue = sb.ToString(); return ReturnValue; } |
Sample Input :
hous-wkvz3-1122845765@craigslist.org Sample out : Check by your self |
|
|
|
|
|