ASCII To UTF8 for Russian - CSharp System

CSharp examples for System:String Unicode

Description

ASCII To UTF8 for Russian

Demo Code


using System.Text;
using System;// ww w  . j  av a  2s .c  om

public class Main{
        public static string ASCIIToUTF8(this string s)
        {
            var found = false;
            char c;
            for (var i = 0; i < s.Length; i++)
            {
                c = s[i];
                if (c.IsRussianASCIIChar())
                {
                    found = true;
                    break;
                }
            }
            if (!found)
            {
                return s;
            }

            var res = new char[s.Length];
            for (var i = 0; i < s.Length; i++)
            {
                c = s[i];
                if (c.IsRussianASCIIChar())
                {
                    res[i] = (char)(c + 0x0350);
                }
                else
                {
                    res[i] = c;
                }
            }
            return new string(res);
        }
        public static bool IsRussianASCIIChar(this char c)
        {
            return c >= '\xC0' && c <= '\xFF';
        }
}

Related Tutorials