Decode Value as String - CSharp System

CSharp examples for System:String Encode Decode

Description

Decode Value as String

Demo Code


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 "&gt;":
                           output.Append( ">" );
                           break;
                        case "&quot;":
                           output.Append( "\"" );
                           break;
                        case "&amp;":
                           output.Append( "&" );
                           break;
                        case "&Aacute;":
                           output.Append( (char) 193 );
                           break;
                        case "&aacute;":
                           output.Append( (char) 225 );
                           break;
                        case "&Acirc;":
                           output.Append( (char) 194 );
                           break;
                        case "&acirc;":
                           output.Append( (char) 226 );
                           break;
                        case "&acute;":
                           output.Append( (char) 180 );
                           break;
                        case "&AElig;":
                           output.Append( (char) 198 );
                           break;
                        case "&aelig;":
                           output.Append( (char) 230 );
                           break;
                        case "&Agrave;":
                           output.Append( (char) 192 );
                           break;
                        case "&agrave;":
                           output.Append( (char) 224 );
                           break;
                        case "&alefsym;":
                           output.Append( (char) 8501 );
                           break;
                        case "&Alpha;":
                           output.Append( (char) 913 );
                           break;
                        case "&alpha;":
                           output.Append( (char) 945 );
                           break;

                        case "&and;":
                           output.Append( (char) 8743 );
                           break;
                        case "&ang;":
                           output.Append( (char) 8736 );
                           break;
                        case "&Aring;":
                           output.Append( (char) 197 );
                           break;
                        case "&aring;":
                           output.Append( (char) 229 );
                           break;
                        case "&asymp;":
                           output.Append( (char) 8776 );
                           break;
                        case "&Atilde;":
                           output.Append( (char) 195 );
                           break;
                        case "&atilde;":
                           output.Append( (char) 227 );
                           break;
                        case "&Auml;":
                           output.Append( (char) 196 );
                           break;
                        case "&auml;":
                           output.Append( (char) 228 );
                           break;
                        case "&bdquo;":
                           output.Append( (char) 8222 );
                           break;
                        case "&Beta;":
                           output.Append( (char) 914 );
                           break;
                        case "&beta;":
                           output.Append( (char) 946 );
                           break;
                        case "&brvbar;":
                           output.Append( (char) 166 );
                           break;
                        case "&bull;":
                           output.Append( (char) 8226 );
                           break;
                        case "&cap;":
                           output.Append( (char) 8745 );
                           break;
                        case "&Ccedil;":
                           output.Append( (char) 199 );
                           break;
                        case "&ccedil;":
                           output.Append( (char) 231 );
                           break;
                        case "&cedil;":
                           output.Append( (char) 184 );
                           break;
                        case "&cent;":
                           output.Append( (char) 162 );
                           break;
                        case "&Chi;":
                           output.Append( (char) 935 );
                           break;
                        case "&chi;":
                           output.Append( (char) 967 );
                           break;
                        case "&circ;":
                           output.Append( (char) 710 );
                           break;
                        case "&clubs;":
                           output.Append( (char) 9827 );
                           break;
                        case "&cong;":
                           output.Append( (char) 8773 );
                           break;
                        case "&copy;":
                           output.Append( (char) 169 );
                           break;
                        case "&crarr;":
                           output.Append( (char) 8629 );
                           break;
                        case "&cup;":
                           output.Append( (char) 8746 );
                           break;
                        case "&curren;":
                           output.Append( (char) 164 );
                           break;
                        case "&dagger;":
                           output.Append( (char) 8224 );
                           break;
                        case "&Dagger;":
                           output.Append( (char) 8225 );
                           break;
                        case "&darr;":
                           output.Append( (char) 8595 );
                           break;
                        case "&dArr;":
                           output.Append( (char) 8659 );
                           break;
                        case "&deg;":
                           output.Append( (char) 176 );
                           break;
                        case "&Delta;":
                           output.Append( (char) 916 );
                           break;
                        case "&delta;":
                           output.Append( (char) 948 );
                           break;
                        case "&diams;":
                           output.Append( (char) 9830 );
                           break;
                        case "&divide;":
                           output.Append( (char) 247 );
                           break;
                        case "&Eacute;":
                           output.Append( (char) 201 );
                           break;
                        case "&eacute;":
                           output.Append( (char) 233 );
                           break;
                        case "&Ecirc;":
                           output.Append( (char) 202 );
                           break;
                        case "&ecirc;":
                           output.Append( (char) 234 );
                           break;

                        case "&Egrave;":
                           output.Append( (char) 200 );
                           break;
                        case "&egrave;":
                           output.Append( (char) 232 );
                           break;
                        case "&empty;":
                           output.Append( (char) 8709 );
                           break;
                        case "&emsp;":
                           output.Append( (char) 8195 );
                           break;
                        case "&Epsilon;":
                           output.Append( (char) 917 );
                           break;
                        case "&epsilon;":
                           output.Append( (char) 949 );
                           break;
                        case "&equiv;":
                           output.Append( (char) 8801 );
                           break;
                        case "&Eta;":
                           output.Append( (char) 919 );
                           break;
                        case "&eta;":
                           output.Append( (char) 951 );
                           break;
                        case "&ETH;":
                           output.Append( (char) 208 );
                           break;
                        case "&eth;":
                           output.Append( (char) 240 );
                           break;
                        case "&Euml;":
                           output.Append( (char) 203 );
                           break;
                        case "&euml;":
                           output.Append( (char) 235 );
                           break;
                        case "&euro;":
                           output.Append( (char) 128 );
                           break;
                        case "&exist;":
                           output.Append( (char) 8707 );
                           break;
                        case "&fnof;":
                           output.Append( (char) 402 );
                           break;
                        case "&forall;":
                           output.Append( (char) 8704 );
                           break;
                        case "&frac12;":
                           output.Append( (char) 189 );
                           break;
                        case "&frac14;":
                           output.Append( (char) 188 );
                           break;
                        case "&frac34;":
                           output.Append( (char) 190 );
                           break;
                        case "&fras1;":
                           output.Append( (char) 8260 );
                           break;
                        case "&Gamma;":
                           output.Append( (char) 915 );
                           break;
                        case "&gamma;":
                           output.Append( (char) 947 );
                           break;
                        case "&ge;":
                           output.Append( (char) 8805 );
                           break;
                        case "&harr;":
                           output.Append( (char) 8596 );
                           break;
                        case "&hArr;":
                           output.Append( (char) 8660 );
                           break;
                        case "&hearts;":
                           output.Append( (char) 9829 );
                           break;
                        case "&hellip;":
                           output.Append( (char) 8230 );
                           break;
                        case "&Iacute;":
                           output.Append( (char) 205 );
                           break;
                        case "&iacute;":
                           output.Append( (char) 237 );
                           break;
                        case "&Icirc;":
                           output.Append( (char) 206 );
                           break;
                        case "&icirc;":
                           output.Append( (char) 238 );
                           break;
                        case "&iexcl;":
                           output.Append( (char) 161 );
                           break;
                        case "&Igrave;":
                           output.Append( (char) 204 );
                           break;
                        case "&igrave;":
                           output.Append( (char) 236 );
                           break;
                        case "&image;":
                           output.Append( (char) 8465 );
                           break;
                        case "&infin;":
                           output.Append( (char) 8734 );
                           break;
                        case "&int;":
                           output.Append( (char) 8747 );
                           break;
                        case "&Iota;":
                           output.Append( (char) 921 );
                           break;

                        case "&iota;":
                           output.Append( (char) 953 );
                           break;
                        case "&iquest;":
                           output.Append( (char) 191 );
                           break;
                        case "&isin;":
                           output.Append( (char) 8712 );
                           break;
                        case "&Iuml;":
                           output.Append( (char) 207 );
                           break;
                        case "&iuml;":
                           output.Append( (char) 239 );
                           break;
                        case "&Kappa;":
                           output.Append( (char) 922 );
                           break;
                        case "&kappa;":
                           output.Append( (char) 954 );
                           break;
                        case "&Lambda;":
                           output.Append( (char) 923 );
                           break;
                        case "&lambda;":
                           output.Append( (char) 955 );
                           break;
                        case "&lang;":
                           output.Append( (char) 9001 );
                           break;
                        case "&laquo;":
                           output.Append( (char) 171 );
                           break;
                        case "&larr;":
                           output.Append( (char) 8592 );
                           break;
                        case "&lArr;":
                           output.Append( (char) 8656 );
                           break;
                        case "&lceil;":
                           output.Append( (char) 8968 );
                           break;
                        case "&ldquo;":
                           output.Append( (char) 8220 );
                           break;
                        case "&le;":
                           output.Append( (char) 8804 );
                           break;
                        case "&lfloor;":
                           output.Append( (char) 8970 );
                           break;
                        case "&lowast;":
                           output.Append( (char) 8727 );
                           break;
                        case "&loz;":
                           output.Append( (char) 9674 );
                           break;
                        case "&lrm;":
                           output.Append( (char) 8206 );
                           break;
                        case "&lsaquo;":
                           output.Append( (char) 8249 );
                           break;
                        case "&lsquo;":
                           output.Append( (char) 8216 );
                           break;
                        case "&macr;":
                           output.Append( (char) 175 );
                           break;
                        case "&mdash;":
                           output.Append( (char) 8212 );
                           break;
                        case "&micro;":
                           output.Append( (char) 181 );
                           break;
                        case "&middot;":
                           output.Append( (char) 183 );
                           break;
                        case "&minus;":
                           output.Append( (char) 8722 );
                           break;
                        case "&Mu;":
                           output.Append( (char) 924 );
                           break;
                        case "&mu;":
                           output.Append( (char) 956 );
                           break;
                        case "&nabla;":
                           output.Append( (char) 8711 );
                           break;
                        case "&nbsp;":
                           output.Append( (char) 160 );
                           break;
                        case "&ndash;":
                           output.Append( (char) 8211 );
                           break;
                        case "&ne;":
                           output.Append( (char) 8800 );
                           break;
                        case "&ni;":
                           output.Append( (char) 8715 );
                           break;
                        case "&not;":
                           output.Append( (char) 172 );
                           break;
                        case "&notin;":
                           output.Append( (char) 8713 );
                           break;
                        case "&nsub;":
                           output.Append( (char) 8836 );
                           break;
                        case "&Ntilde;":
                           output.Append( (char) 209 );
                           break;
                        case "&ntilde;":
                           output.Append( (char) 241 );
                           break;
                        case "&Nu;":
                           output.Append( (char) 925 );
                           break;

                        case "&nu;":
                           output.Append( (char) 957 );
                           break;
                        case "&Oacute;":
                           output.Append( (char) 211 );
                           break;
                        case "&oacute;":
                           output.Append( (char) 243 );
                           break;
                        case "&Ocirc;":
                           output.Append( (char) 212 );
                           break;
                        case "&ocirc;":
                           output.Append( (char) 244 );
                           break;
                        case "&OElig;":
                           output.Append( (char) 338 );
                           break;
                        case "&oelig;":
                           output.Append( (char) 339 );
                           break;
                        case "&Ograve;":
                           output.Append( (char) 210 );
                           break;
                        case "&ograve;":
                           output.Append( (char) 242 );
                           break;
                        case "&oline;":
                           output.Append( (char) 8254 );
                           break;
                        case "&Omega;":
                           output.Append( (char) 937 );
                           break;
                        case "&omega;":
                           output.Append( (char) 969 );
                           break;
                        case "&Omicron;":
                           output.Append( (char) 927 );
                           break;
                        case "&omicron;":
                           output.Append( (char) 959 );
                           break;
                        case "&oplus;":
                           output.Append( (char) 8853 );
                           break;
                        case "&or;":
                           output.Append( (char) 8744 );
                           break;
                        case "&ordf;":
                           output.Append( (char) 170 );
                           break;
                        case "&ordm;":
                           output.Append( (char) 186 );
                           break;
                        case "&Oslash;":
                           output.Append( (char) 216 );
                           break;
                        case "&oslash;":
                           output.Append( (char) 248 );
                           break;
                        case "&Otilde;":
                           output.Append( (char) 213 );
                           break;
                        case "&otilde;":
                           output.Append( (char) 245 );
                           break;
                        case "&otimes;":
                           output.Append( (char) 8855 );
                           break;
                        case "&Ouml;":
                           output.Append( (char) 214 );
                           break;
                        case "&ouml;":
                           output.Append( (char) 246 );
                           break;
                        case "&para;":
                           output.Append( (char) 182 );
                           break;
                        case "&part;":
                           output.Append( (char) 8706 );
                           break;
                        case "&permil;":
                           output.Append( (char) 8240 );
                           break;
                        case "&perp;":
                           output.Append( (char) 8869 );
                           break;
                        case "&Phi;":
                           output.Append( (char) 934 );
                           break;
                        case "&phi;":
                           output.Append( (char) 966 );
                           break;
                        case "&Pi;":
                           output.Append( (char) 928 );
                           break;
                        case "&pi;":
                           output.Append( (char) 960 );
                           break;
                        case "&piv;":
                           output.Append( (char) 982 );
                           break;
                        case "&plusmn;":
                           output.Append( (char) 177 );
                           break;
                        case "&pound;":
                           output.Append( (char) 163 );
                           break;
                        case "&prime;":
                           output.Append( (char) 8242 );
                           break;
                        case "&Prime;":
                           output.Append( (char) 8243 );
                           break;
                        case "&prod;":
                           output.Append( (char) 8719 );
                           break;
                        case "&prop;":
                           output.Append( (char) 8733 );
                           break;
                        case "&Psi;":
                           output.Append( (char) 936 );
                           break;

                        case "&psi;":
                           output.Append( (char) 968 );
                           break;
                        case "&radic;":
                           output.Append( (char) 8730 );
                           break;
                        case "&rang;":
                           output.Append( (char) 9002 );
                           break;
                        case "&raquo;":
                           output.Append( (char) 187 );
                           break;
                        case "&rarr;":
                           output.Append( (char) 8594 );
                           break;
                        case "&rArr;":
                           output.Append( (char) 8658 );
                           break;
                        case "&rceil;":
                           output.Append( (char) 8969 );
                           break;
                        case "&rdquo;":
                           output.Append( (char) 8221 );
                           break;
                        case "&real;":
                           output.Append( (char) 8476 );
                           break;
                        case "&reg;":
                           output.Append( (char) 174 );
                           break;
                        case "&rfloor;":
                           output.Append( (char) 8971 );
                           break;
                        case "&Rho;":
                           output.Append( (char) 929 );
                           break;
                        case "&rho;":
                           output.Append( (char) 961 );
                           break;
                        case "&rlm;":
                           output.Append( (char) 8207 );
                           break;
                        case "&rsaquo;":
                           output.Append( (char) 8250 );
                           break;
                        case "&rsquo;":
                           output.Append( (char) 8217 );
                           break;
                        case "&sbquo;":
                           output.Append( (char) 8218 );
                           break;
                        case "&Scaron;":
                           output.Append( (char) 352 );
                           break;
                        case "&scaron;":
                           output.Append( (char) 353 );
                           break;
                        case "&sdot;":
                           output.Append( (char) 8901 );
                           break;
                        case "&sect;":
                           output.Append( (char) 167 );
                           break;
                        case "&shy;":
                           output.Append( (char) 173 );
                           break;
                        case "&Sigma;":
                           output.Append( (char) 931 );
                           break;
                        case "&sigma;":
                           output.Append( (char) 963 );
                           break;
                        case "&sigmaf;":
                           output.Append( (char) 962 );
                           break;
                        case "&sim;":
                           output.Append( (char) 8764 );
                           break;
                        case "&spades;":
                           output.Append( (char) 9824 );
                           break;
                        case "&sub;":
                           output.Append( (char) 8834 );
                           break;
                        case "&sube;":
                           output.Append( (char) 8838 );
                           break;
                        case "&sum;":
                           output.Append( (char) 8721 );
                           break;
                        case "&sup;":
                           output.Append( (char) 8835 );
                           break;
                        case "&sup1;":
                           output.Append( (char) 185 );
                           break;
                        case "&sup2;":
                           output.Append( (char) 178 );
                           break;
                        case "&sup3;":
                           output.Append( (char) 179 );
                           break;
                        case "&supe;":
                           output.Append( (char) 8839 );
                           break;
                        case "&szlig;":
                           output.Append( (char) 223 );
                           break;
                        case "&Tau;":
                           output.Append( (char) 932 );
                           break;
                        case "&tau;":
                           output.Append( (char) 964 );
                           break;
                        case "&there4;":
                           output.Append( (char) 8756 );
                           break;
                        case "&Theta;":
                           output.Append( (char) 920 );
                           break;

                        case "&theta;":
                           output.Append( (char) 952 );
                           break;
                        case "&thetasym;":
                           output.Append( (char) 977 );
                           break;
                        case "&thinsp;":
                           output.Append( (char) 8201 );
                           break;
                        case "&THORN;":
                           output.Append( (char) 222 );
                           break;
                        case "&thorn;":
                           output.Append( (char) 254 );
                           break;
                        case "&tilde;":
                           output.Append( (char) 732 );
                           break;
                        case "&times;":
                           output.Append( (char) 215 );
                           break;
                        case "&trade;":
                           output.Append( (char) 8482 );
                           break;
                        case "&Uacute;":
                           output.Append( (char) 218 );
                           break;
                        case "&uacute;":
                           output.Append( (char) 250 );
                           break;
                        case "&uarr;":
                           output.Append( (char) 8593 );
                           break;
                        case "&uArr;":
                           output.Append( (char) 8657 );
                           break;
                        case "&Ucirc;":
                           output.Append( (char) 219 );
                           break;
                        case "&ucirc;":
                           output.Append( (char) 251 );
                           break;
                        case "&Ugrave;":
                           output.Append( (char) 217 );
                           break;
                        case "&ugrave;":
                           output.Append( (char) 249 );
                           break;
                        case "&uml;":
                           output.Append( (char) 168 );
                           break;
                        case "&upsih;":
                           output.Append( (char) 978 );
                           break;
                        case "&Upsilon;":
                           output.Append( (char) 933 );
                           break;
                        case "&upsilon;":
                           output.Append( (char) 965 );
                           break;
                        case "&Uuml;":
                           output.Append( (char) 220 );
                           break;
                        case "&uuml;":
                           output.Append( (char) 252 );
                           break;
                        case "&weierp;":
                           output.Append( (char) 8472 );
                           break;
                        case "&Xi;":
                           output.Append( (char) 926 );
                           break;
                        case "&xi;":
                           output.Append( (char) 958 );
                           break;
                        case "&Yacute;":
                           output.Append( (char) 221 );
                           break;
                        case "&yacute;":
                           output.Append( (char) 253 );
                           break;
                        case "&yen;":
                           output.Append( (char) 165 );
                           break;
                        case "&Yuml;":
                           output.Append( (char) 376 );
                           break;
                        case "&yuml;":
                           output.Append( (char) 255 );
                           break;
                        case "&Zeta;":
                           output.Append( (char) 918 );
                           break;
                        case "&zeta;":
                           output.Append( (char) 950 );
                           break;
                        case "&zwj;":
                           output.Append( (char) 8205 );
                           break;
                        case "&zwnj;":
                           output.Append( (char) 8204 );
                           break;

                        default:
                           output.Append( token.ToString() );
                           break;
                     }
                  }
               }
               else
               {
                  output.Append( token.ToString() );
               }
            }
         }
         return output.ToString();
      }
}

Related Tutorials