.NET: Detect String Encoding
By admin on Mar 15, 2009 in .NET, Programming
Here is a simple way to detect if your content is ASCII or Unicode
public void CheckForEncoding(string content)
{
int i = 0;
for (i = 1; i <= content.Length; i++)
{
int code = Convert.ToInt32(Convert.ToChar(content.Substring(i - 1, 1))) ;
if (code < 0 || code > 255)
{
Console.WriteLine("Unicode");
return;
}
}
Console.WriteLine("ascii");
}
Popularity: 2% [?]
Post a Comment