static void Main(string[] args)
    {
        String[] sign = new String[] { "<", "=", ">" };

        // The code below demonstrates how strings compare
        // differently for different cultures.
        String s1 = "Coté", s2 = "coté", s3 = "côte";

        // Set sort order of strings for French in France.
        CompareInfo ci = new CultureInfo("fr-FR").CompareInfo;

        Console.WriteLine("The LCID for {0} is {1}.", ci.Name, ci.LCID);

        // Display the result using fr-FR Compare of Coté = coté.
        Console.WriteLine("fr-FR Compare: {0} {2} {1}",
                          s1, s2, sign[ci.Compare(s1, s2, CompareOptions.IgnoreCase) + 1]);

        // Display the result using fr-FR Compare of coté > côte.
        Console.WriteLine("fr-FR Compare: {0} {2} {1}",
                          s2, s3, sign[ci.Compare(s2, s3, CompareOptions.None) + 1]);

        // Set sort order of strings for Japanese as spoken in Japan.
        ci = new CultureInfo("ja-JP").CompareInfo;
        Console.WriteLine("The LCID for {0} is {1}.", ci.Name, ci.LCID);

        // Display the result using ja-JP Compare of coté < côte.
        Console.WriteLine("ja-JP Compare: {0} {2} {1}",
                          s2, s3, sign[ci.Compare(s2, s3) + 1]);
    }
Пример #2
0
        public static bool EqualCaseAndAccentInsensitive(this string @this, string other)
        {
            var ci = new CultureInfo("en-US").CompareInfo;
            var co = CompareOptions.IgnoreCase | CompareOptions.IgnoreNonSpace;

            return(ci.Compare(@this, other, co) == 0);
        }
Пример #3
0
        public static int CompararSemAcentos(string a, string b)
        {
            CompareInfo    ci = new CultureInfo("pt-BR").CompareInfo;
            CompareOptions co = CompareOptions.IgnoreCase | CompareOptions.IgnoreNonSpace;

            return(ci.Compare(a.Trim(), b.Trim(), co));
        }
Пример #4
0
        public static void Compare()
        {
            string      searchString = "This is the search string";
            string      searchVal    = "ing";
            CompareInfo comparer     = new CultureInfo("it-IT").CompareInfo;

            Console.WriteLine(comparer.Compare(searchString, searchVal) > 0);
        }
Пример #5
0
        static void CompareIgnoreZenHanUpperLower(string str1, string str2)
        {
            var compareInfo = new CultureInfo("ja-JP").CompareInfo;

            if (compareInfo.Compare(str1, str2, CompareOptions.IgnoreWidth | CompareOptions.IgnoreCase) == 0)
            {
                Console.WriteLine("一致しています");
            }
        }
        public static void CompareInfoBasicTests()
        {
            string one        = "A test string";
            string aCopyOfOne = one;

            StringComparer comp = new CultureInfo("fr-FR").CompareInfo.GetStringComparer(CompareOptions.IgnoreCase);

            Assert.Equal(0, comp.Compare(one, aCopyOfOne));
            Assert.True(comp.Equals(one, aCopyOfOne));

            Assert.Equal(-1, comp.Compare(null, one));
            Assert.Equal(0, comp.Compare(null, null));
            Assert.Equal(1, comp.Compare(one, null));

            Assert.False(comp.Equals(null, one));
            Assert.True(comp.Equals(null, null));
            Assert.False(comp.Equals(one, null));

            Assert.Equal(comp.GetHashCode("abc"), comp.GetHashCode("ABC"));
        }
        public static void CompareInfoBasicTests()
        {
            string one = "A test string";
            string aCopyOfOne = one;

            StringComparer comp = new CultureInfo("fr-FR").CompareInfo.GetStringComparer(CompareOptions.IgnoreCase);

            Assert.Equal(0, comp.Compare(one, aCopyOfOne));
            Assert.True(comp.Equals(one, aCopyOfOne));

            Assert.Equal(-1, comp.Compare(null, one));
            Assert.Equal(0, comp.Compare(null, null));
            Assert.Equal(1, comp.Compare(one, null));

            Assert.False(comp.Equals(null, one));
            Assert.True(comp.Equals(null, null));
            Assert.False(comp.Equals(one, null));

            Assert.Equal(comp.GetHashCode("abc"), comp.GetHashCode("ABC"));
        }
        public static void Compare(string x, string y, string cultureName, CompareOptions options, int expectedWindows, int expectedICU)
        {
            int            expected = s_isWindows ? expectedWindows : expectedICU;
            StringComparer comparer = new CultureInfo(cultureName).CompareInfo.GetStringComparer(options);

            Assert.Equal(expected, Math.Sign(comparer.Compare(x, y)));
            Assert.Equal((expected == 0), comparer.Equals(x, y));

            if (x != null && y != null)
            {
                Assert.Equal((expected == 0), comparer.GetHashCode(x).Equals(comparer.GetHashCode(y)));
            }
        }
Пример #9
0
        public static void Compare(string x, string y, string cultureName, CompareOptions options, int expectedWindows, int expectedICU)
        {
            int expected = s_isWindows ? expectedWindows : expectedICU;
            StringComparer comparer = new CultureInfo(cultureName).CompareInfo.GetStringComparer(options);

            Assert.Equal(expected, Math.Sign(comparer.Compare(x, y)));
            Assert.Equal((expected == 0), comparer.Equals(x, y));

            if (x != null && y != null)
            {
                Assert.Equal((expected == 0), comparer.GetHashCode(x).Equals(comparer.GetHashCode(y)));
            }
        }
Пример #10
0
        public static void Compare(string x, string y, string cultureName, CompareOptions options, int expectedNls, int expectedICU)
        {
            int            expected = PlatformDetection.IsNlsGlobalization ? expectedNls : expectedICU;
            StringComparer comparer = new CultureInfo(cultureName).CompareInfo.GetStringComparer(options);

            Assert.Equal(expected, Math.Sign(comparer.Compare(x, y)));
            Assert.Equal((expected == 0), comparer.Equals(x, y));

            if (x != null && y != null)
            {
                Assert.Equal((expected == 0), comparer.GetHashCode(x).Equals(comparer.GetHashCode(y)));
            }
        }
        public static void CompareVarying(string one, string two, int compareValue, string culture, CompareOptions compareOptions)
        {
            StringComparer comp = new CultureInfo(culture).CompareInfo.GetStringComparer(compareOptions);

            Assert.Equal(compareValue, comp.Compare(one, two));
            if (compareValue == 0)
            {
                Assert.True(comp.Equals(one, two));
            }
            else
            {
                Assert.False(comp.Equals(one, two));
            }
        }
        private static void CompareVarying(string one, string two, int compareValue, string culture, CompareOptions compareOptions)
        {
            StringComparer comp = new CultureInfo(culture).CompareInfo.GetStringComparer(compareOptions);

            Assert.Equal(compareValue, comp.Compare(one, two));
            if (compareValue == 0)
            {
                Assert.True(comp.Equals(one, two));
            }
            else
            {
                Assert.False(comp.Equals(one, two));
            }
        }
Пример #13
0
        protected void cvVille_ServerValidate(object source, ServerValidateEventArgs args)
        {
            string[] villes = { "Quebec", "Montreal", "Levis" };

            CompareInfo ci = new CultureInfo("fr-CA").CompareInfo;

            if (villes.Any(ville => ci.Compare(
                               ville, args.Value, CompareOptions.IgnoreNonSpace
                               ) == 0
                           )
                )
            {
                args.IsValid = true;
            }
            else
            {
                args.IsValid = false;
            }
        }
Пример #14
0
        protected override void SendTextMessage()
        {
            string text = m_Field.text.Trim();

            if (!text.StartsWith("/tp"))
            {
                base.SendTextMessage();
            }
            else
            {
                CompareInfo caseInsensitiveComparer = new CultureInfo("en-US").CompareInfo;

                string playerName = text.Substring(3).Trim();
                foreach (ReplicatedLogicalPlayer player in ReplicatedLogicalPlayer.s_AllLogicalPlayers)
                {
                    if (caseInsensitiveComparer.Compare(playerName, player.GetP2PPeer().GetDisplayName(), CompareOptions.IgnoreCase | CompareOptions.IgnoreNonSpace) == 0)
                    {
                        Player.Get().Teleport(player.gameObject, false);
                        break;
                    }
                }
            }
        }
Пример #15
0
        static void Main(string[] args)
        {
            //MailTest();
            CultureInfo usercul = System.Threading.Thread.CurrentThread.CurrentCulture;

            Console.WriteLine("The current culture of this app is :" + usercul.Name);
            Console.WriteLine("The Dispaly name of this app is :" + usercul.DisplayName);
            Console.WriteLine("The Native name of this app is :" + usercul.NativeName);
            Console.WriteLine("The ISO abbreviation of this app is :" + usercul.TwoLetterISOLanguageName);
            string cur = (100000).ToString("C");

            Console.WriteLine(cur);
            usercul = System.Threading.Thread.CurrentThread.CurrentUICulture;
            Console.WriteLine("The current culture of this app is :" + usercul.Name);
            Console.WriteLine("The Dispaly name of this app is :" + usercul.DisplayName);
            Console.WriteLine("The Native name of this app is :" + usercul.NativeName);
            Console.WriteLine("The ISO abbreviation of this app is :" + usercul.TwoLetterISOLanguageName);
            System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("es-VE");
            Console.WriteLine("The current culture of this app is :" + System.Threading.Thread.CurrentThread.CurrentCulture);
            foreach (CultureInfo cul in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
            {
                Console.WriteLine("culture:" + cul.Name);
            }
            usercul = System.Threading.Thread.CurrentThread.CurrentCulture;
            RegionInfo ri = new RegionInfo(usercul.LCID);

            //OR
            ri = new RegionInfo(usercul.Name);
            Console.WriteLine("English name: " + ri.EnglishName);
            Console.WriteLine("Display name: " + ri.DisplayName);
            Console.WriteLine("Currency Symbol: " + ri.CurrencySymbol);
            string[] days = usercul.DateTimeFormat.DayNames;
            foreach (string day in days)
            {
                Console.WriteLine("Day name for Venezuelan Spanish: " + day);
            }
            string[] months = usercul.DateTimeFormat.MonthNames;
            foreach (string mon in months)
            {
                Console.WriteLine("Month name in Venz. Spanish:" + mon);
            }
            Console.WriteLine("Number decimal Symbol:" + usercul.NumberFormat.NumberDecimalSeparator);
            CompareInfo ci = System.Threading.Thread.CurrentThread.CurrentUICulture.CompareInfo;

            Console.WriteLine(ci.Name);
            Console.WriteLine(ci.LCID);
            string firstString  = "Coté";
            string secondString = "coté";

            ci = new CultureInfo("fr-FR").CompareInfo;
            Console.WriteLine(ci.Compare(firstString, secondString));
            Console.WriteLine(ci.Compare(firstString, secondString, CompareOptions.IgnoreCase));
            CultureAndRegionInfoBuilder build = new CultureAndRegionInfoBuilder("en-MS", CultureAndRegionModifiers.None);
            CultureInfo USCulture             = new CultureInfo("en-US");
            RegionInfo  USRegion = new RegionInfo("US");

            build.LoadDataFromCultureInfo(USCulture);
            build.LoadDataFromRegionInfo(USRegion);
            build.NumberFormat.CurrencySymbol           = "*";
            build.NumberFormat.CurrencyDecimalSeparator = "^";
            build.Save(@"c:\msft.culture.xml");


            //build.Register();
            //System.Threading.Thread.CurrentThread.CurrentCultu
        }