ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

IsUnicode

IsUnicode

Source

public static bool IsUnicode(this string value)
{
   int asciiBytesCount = System.Text.Encoding.ASCII.GetByteCount(value);
   int unicodBytesCount = System.Text.Encoding.UTF8.GetByteCount(value);

    if (asciiBytesCount != unicodBytesCount)
    {
        return true;
    }
    return false;
}

Example

bool isUnicode = "سید مهدی میری".IsUnicode();

Author: Mehdi Miri

Submitted on: 26 mrt. 2013

Language: C#

Type: System.String

Views: 7669