Skip to content

Instantly share code, notes, and snippets.

@renestein
Created December 6, 2010 09:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renestein/730046 to your computer and use it in GitHub Desktop.
Save renestein/730046 to your computer and use it in GitHub Desktop.
public static class StringExtensions
{
public static readonly string CHAR_UNICODE_FORMAT = "&#{0};";
public static readonly int ASCII_INDEX = 127;
//Dirty fix for WP7 browser
public static string EncodeUnicodeChars(this string srcString)
{
if (srcString == null)
{
throw new ArgumentNullException("srcString");
}
var resultString = srcString.Aggregate(new StringBuilder(),
(sb, ch) =>
{
var intCh = (int) ch;
if (intCh > ASCII_INDEX )
{
sb.AppendFormat(CHAR_UNICODE_FORMAT, intCh);
}
else
{
sb.Append(ch);
}
return sb;
},
sb => sb.ToString()
);
return resultString;
}
}
@rarous
Copy link

rarous commented Dec 6, 2010

pozor, intCh neni nikde použito, myslím, že by mělo být na následujících dvou řádcích...

@renestein
Copy link
Author

Díky, opraveno. To je tak, když si dá člověk v půli refaktorizace panáka, aby přežil ty WP7 dary.:)
BTW: Diky za doporučení GISTů Aleši.

@rarous
Copy link

rarous commented Dec 6, 2010

udělal jsem to hlavně kvůli sobě :)

@renestein
Copy link
Author

A pak že sobectví není druh altruismu.;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment