CSharp examples for System:String Encode Decode
Decode Value as String
using System.Text; using System.IO;//from w ww . j a v a 2 s . c o m using System; public class Main{ public static string DecodeValue(string value) { StringBuilder output = new StringBuilder(); StringReader reader = new StringReader( value ); StringBuilder token; int c = reader.Read(); while( c != -1 ) { token = new StringBuilder(); while( c != '&' && c != -1 ) { token.Append( (char) c ); c = reader.Read(); } output.Append( token.ToString() ); if( c == '&' ) { token = new StringBuilder(); while( c != ';' && c != -1 ) { token.Append( (char) c ); c = reader.Read(); } if( c == ';' ) { c = reader.Read(); token.Append( ';' ); if( token[1] == '#' ) { int v = int.Parse( token.ToString().Substring(2,token.Length-3) ); output.Append( (char) v ); } else { switch( token.ToString() ) { case "<": output.Append( "<" ); break; case ">": output.Append( ">" ); break; case """: output.Append( "\"" ); break; case "&": output.Append( "&" ); break; case "Á": output.Append( (char) 193 ); break; case "á": output.Append( (char) 225 ); break; case "Â": output.Append( (char) 194 ); break; case "â": output.Append( (char) 226 ); break; case "´": output.Append( (char) 180 ); break; case "Æ": output.Append( (char) 198 ); break; case "æ": output.Append( (char) 230 ); break; case "À": output.Append( (char) 192 ); break; case "à": output.Append( (char) 224 ); break; case "ℵ": output.Append( (char) 8501 ); break; case "Α": output.Append( (char) 913 ); break; case "α": output.Append( (char) 945 ); break; case "∧": output.Append( (char) 8743 ); break; case "∠": output.Append( (char) 8736 ); break; case "Å": output.Append( (char) 197 ); break; case "å": output.Append( (char) 229 ); break; case "≈": output.Append( (char) 8776 ); break; case "Ã": output.Append( (char) 195 ); break; case "ã": output.Append( (char) 227 ); break; case "Ä": output.Append( (char) 196 ); break; case "ä": output.Append( (char) 228 ); break; case "„": output.Append( (char) 8222 ); break; case "Β": output.Append( (char) 914 ); break; case "β": output.Append( (char) 946 ); break; case "¦": output.Append( (char) 166 ); break; case "•": output.Append( (char) 8226 ); break; case "∩": output.Append( (char) 8745 ); break; case "Ç": output.Append( (char) 199 ); break; case "ç": output.Append( (char) 231 ); break; case "¸": output.Append( (char) 184 ); break; case "¢": output.Append( (char) 162 ); break; case "Χ": output.Append( (char) 935 ); break; case "χ": output.Append( (char) 967 ); break; case "ˆ": output.Append( (char) 710 ); break; case "♣": output.Append( (char) 9827 ); break; case "≅": output.Append( (char) 8773 ); break; case "©": output.Append( (char) 169 ); break; case "↵": output.Append( (char) 8629 ); break; case "∪": output.Append( (char) 8746 ); break; case "¤": output.Append( (char) 164 ); break; case "†": output.Append( (char) 8224 ); break; case "‡": output.Append( (char) 8225 ); break; case "↓": output.Append( (char) 8595 ); break; case "⇓": output.Append( (char) 8659 ); break; case "°": output.Append( (char) 176 ); break; case "Δ": output.Append( (char) 916 ); break; case "δ": output.Append( (char) 948 ); break; case "♦": output.Append( (char) 9830 ); break; case "÷": output.Append( (char) 247 ); break; case "É": output.Append( (char) 201 ); break; case "é": output.Append( (char) 233 ); break; case "Ê": output.Append( (char) 202 ); break; case "ê": output.Append( (char) 234 ); break; case "È": output.Append( (char) 200 ); break; case "è": output.Append( (char) 232 ); break; case "∅": output.Append( (char) 8709 ); break; case " ": output.Append( (char) 8195 ); break; case "Ε": output.Append( (char) 917 ); break; case "ε": output.Append( (char) 949 ); break; case "≡": output.Append( (char) 8801 ); break; case "Η": output.Append( (char) 919 ); break; case "η": output.Append( (char) 951 ); break; case "Ð": output.Append( (char) 208 ); break; case "ð": output.Append( (char) 240 ); break; case "Ë": output.Append( (char) 203 ); break; case "ë": output.Append( (char) 235 ); break; case "€": output.Append( (char) 128 ); break; case "∃": output.Append( (char) 8707 ); break; case "ƒ": output.Append( (char) 402 ); break; case "∀": output.Append( (char) 8704 ); break; case "½": output.Append( (char) 189 ); break; case "¼": output.Append( (char) 188 ); break; case "¾": output.Append( (char) 190 ); break; case "&fras1;": output.Append( (char) 8260 ); break; case "Γ": output.Append( (char) 915 ); break; case "γ": output.Append( (char) 947 ); break; case "≥": output.Append( (char) 8805 ); break; case "↔": output.Append( (char) 8596 ); break; case "⇔": output.Append( (char) 8660 ); break; case "♥": output.Append( (char) 9829 ); break; case "…": output.Append( (char) 8230 ); break; case "Í": output.Append( (char) 205 ); break; case "í": output.Append( (char) 237 ); break; case "Î": output.Append( (char) 206 ); break; case "î": output.Append( (char) 238 ); break; case "¡": output.Append( (char) 161 ); break; case "Ì": output.Append( (char) 204 ); break; case "ì": output.Append( (char) 236 ); break; case "ℑ": output.Append( (char) 8465 ); break; case "∞": output.Append( (char) 8734 ); break; case "∫": output.Append( (char) 8747 ); break; case "Ι": output.Append( (char) 921 ); break; case "ι": output.Append( (char) 953 ); break; case "¿": output.Append( (char) 191 ); break; case "∈": output.Append( (char) 8712 ); break; case "Ï": output.Append( (char) 207 ); break; case "ï": output.Append( (char) 239 ); break; case "Κ": output.Append( (char) 922 ); break; case "κ": output.Append( (char) 954 ); break; case "Λ": output.Append( (char) 923 ); break; case "λ": output.Append( (char) 955 ); break; case "⟨": output.Append( (char) 9001 ); break; case "«": output.Append( (char) 171 ); break; case "←": output.Append( (char) 8592 ); break; case "⇐": output.Append( (char) 8656 ); break; case "⌈": output.Append( (char) 8968 ); break; case "“": output.Append( (char) 8220 ); break; case "≤": output.Append( (char) 8804 ); break; case "⌊": output.Append( (char) 8970 ); break; case "∗": output.Append( (char) 8727 ); break; case "◊": output.Append( (char) 9674 ); break; case "‎": output.Append( (char) 8206 ); break; case "‹": output.Append( (char) 8249 ); break; case "‘": output.Append( (char) 8216 ); break; case "¯": output.Append( (char) 175 ); break; case "—": output.Append( (char) 8212 ); break; case "µ": output.Append( (char) 181 ); break; case "·": output.Append( (char) 183 ); break; case "−": output.Append( (char) 8722 ); break; case "Μ": output.Append( (char) 924 ); break; case "μ": output.Append( (char) 956 ); break; case "∇": output.Append( (char) 8711 ); break; case " ": output.Append( (char) 160 ); break; case "–": output.Append( (char) 8211 ); break; case "≠": output.Append( (char) 8800 ); break; case "∋": output.Append( (char) 8715 ); break; case "¬": output.Append( (char) 172 ); break; case "∉": output.Append( (char) 8713 ); break; case "⊄": output.Append( (char) 8836 ); break; case "Ñ": output.Append( (char) 209 ); break; case "ñ": output.Append( (char) 241 ); break; case "Ν": output.Append( (char) 925 ); break; case "ν": output.Append( (char) 957 ); break; case "Ó": output.Append( (char) 211 ); break; case "ó": output.Append( (char) 243 ); break; case "Ô": output.Append( (char) 212 ); break; case "ô": output.Append( (char) 244 ); break; case "Œ": output.Append( (char) 338 ); break; case "œ": output.Append( (char) 339 ); break; case "Ò": output.Append( (char) 210 ); break; case "ò": output.Append( (char) 242 ); break; case "‾": output.Append( (char) 8254 ); break; case "Ω": output.Append( (char) 937 ); break; case "ω": output.Append( (char) 969 ); break; case "Ο": output.Append( (char) 927 ); break; case "ο": output.Append( (char) 959 ); break; case "⊕": output.Append( (char) 8853 ); break; case "∨": output.Append( (char) 8744 ); break; case "ª": output.Append( (char) 170 ); break; case "º": output.Append( (char) 186 ); break; case "Ø": output.Append( (char) 216 ); break; case "ø": output.Append( (char) 248 ); break; case "Õ": output.Append( (char) 213 ); break; case "õ": output.Append( (char) 245 ); break; case "⊗": output.Append( (char) 8855 ); break; case "Ö": output.Append( (char) 214 ); break; case "ö": output.Append( (char) 246 ); break; case "¶": output.Append( (char) 182 ); break; case "∂": output.Append( (char) 8706 ); break; case "‰": output.Append( (char) 8240 ); break; case "⊥": output.Append( (char) 8869 ); break; case "Φ": output.Append( (char) 934 ); break; case "φ": output.Append( (char) 966 ); break; case "Π": output.Append( (char) 928 ); break; case "π": output.Append( (char) 960 ); break; case "ϖ": output.Append( (char) 982 ); break; case "±": output.Append( (char) 177 ); break; case "£": output.Append( (char) 163 ); break; case "′": output.Append( (char) 8242 ); break; case "″": output.Append( (char) 8243 ); break; case "∏": output.Append( (char) 8719 ); break; case "∝": output.Append( (char) 8733 ); break; case "Ψ": output.Append( (char) 936 ); break; case "ψ": output.Append( (char) 968 ); break; case "√": output.Append( (char) 8730 ); break; case "⟩": output.Append( (char) 9002 ); break; case "»": output.Append( (char) 187 ); break; case "→": output.Append( (char) 8594 ); break; case "⇒": output.Append( (char) 8658 ); break; case "⌉": output.Append( (char) 8969 ); break; case "”": output.Append( (char) 8221 ); break; case "ℜ": output.Append( (char) 8476 ); break; case "®": output.Append( (char) 174 ); break; case "⌋": output.Append( (char) 8971 ); break; case "Ρ": output.Append( (char) 929 ); break; case "ρ": output.Append( (char) 961 ); break; case "‏": output.Append( (char) 8207 ); break; case "›": output.Append( (char) 8250 ); break; case "’": output.Append( (char) 8217 ); break; case "‚": output.Append( (char) 8218 ); break; case "Š": output.Append( (char) 352 ); break; case "š": output.Append( (char) 353 ); break; case "⋅": output.Append( (char) 8901 ); break; case "§": output.Append( (char) 167 ); break; case "­": output.Append( (char) 173 ); break; case "Σ": output.Append( (char) 931 ); break; case "σ": output.Append( (char) 963 ); break; case "ς": output.Append( (char) 962 ); break; case "∼": output.Append( (char) 8764 ); break; case "♠": output.Append( (char) 9824 ); break; case "⊂": output.Append( (char) 8834 ); break; case "⊆": output.Append( (char) 8838 ); break; case "∑": output.Append( (char) 8721 ); break; case "⊃": output.Append( (char) 8835 ); break; case "¹": output.Append( (char) 185 ); break; case "²": output.Append( (char) 178 ); break; case "³": output.Append( (char) 179 ); break; case "⊇": output.Append( (char) 8839 ); break; case "ß": output.Append( (char) 223 ); break; case "Τ": output.Append( (char) 932 ); break; case "τ": output.Append( (char) 964 ); break; case "∴": output.Append( (char) 8756 ); break; case "Θ": output.Append( (char) 920 ); break; case "θ": output.Append( (char) 952 ); break; case "ϑ": output.Append( (char) 977 ); break; case " ": output.Append( (char) 8201 ); break; case "Þ": output.Append( (char) 222 ); break; case "þ": output.Append( (char) 254 ); break; case "˜": output.Append( (char) 732 ); break; case "×": output.Append( (char) 215 ); break; case "™": output.Append( (char) 8482 ); break; case "Ú": output.Append( (char) 218 ); break; case "ú": output.Append( (char) 250 ); break; case "↑": output.Append( (char) 8593 ); break; case "⇑": output.Append( (char) 8657 ); break; case "Û": output.Append( (char) 219 ); break; case "û": output.Append( (char) 251 ); break; case "Ù": output.Append( (char) 217 ); break; case "ù": output.Append( (char) 249 ); break; case "¨": output.Append( (char) 168 ); break; case "ϒ": output.Append( (char) 978 ); break; case "Υ": output.Append( (char) 933 ); break; case "υ": output.Append( (char) 965 ); break; case "Ü": output.Append( (char) 220 ); break; case "ü": output.Append( (char) 252 ); break; case "℘": output.Append( (char) 8472 ); break; case "Ξ": output.Append( (char) 926 ); break; case "ξ": output.Append( (char) 958 ); break; case "Ý": output.Append( (char) 221 ); break; case "ý": output.Append( (char) 253 ); break; case "¥": output.Append( (char) 165 ); break; case "Ÿ": output.Append( (char) 376 ); break; case "ÿ": output.Append( (char) 255 ); break; case "Ζ": output.Append( (char) 918 ); break; case "ζ": output.Append( (char) 950 ); break; case "‍": output.Append( (char) 8205 ); break; case "‌": output.Append( (char) 8204 ); break; default: output.Append( token.ToString() ); break; } } } else { output.Append( token.ToString() ); } } } return output.ToString(); } }