private int LinearIndexOf(string fieldName, CompareOptions compareOptions)
        {
            CompareInfo compareInfo = this._compareInfo;

            if (compareInfo == null)
            {
                if (-1 != this._defaultLocaleID)
                {
                    compareInfo = CompareInfo.GetCompareInfo(this._defaultLocaleID);
                }
                if (compareInfo == null)
                {
                    compareInfo = CultureInfo.InvariantCulture.CompareInfo;
                }
                this._compareInfo = compareInfo;
            }
            int length = this._fieldNames.Length;

            for (int i = 0; i < length; i++)
            {
                if (compareInfo.Compare(fieldName, this._fieldNames[i], compareOptions) == 0)
                {
                    this._fieldNameLookup[fieldName] = i;
                    return(i);
                }
            }
            return(-1);
        }
예제 #2
0
        /**
         * Convenience override of getDisplayNames(UCultureInfo, Comparer, string) that
         * uses the default collator for the locale as the comparator to
         * sort the display names.
         */
        public IDictionary <string, string> GetDisplayNames(ICUService service, UCultureInfo locale, string matchID)
        {
            //Collator col = Collator.getInstance(locale.toLocale());
            CompareInfo col = CompareInfo.GetCompareInfo(locale.ToCultureInfo().Name);

            return(service.GetDisplayNames(locale, col, matchID));
        }
예제 #3
0
        public void Execute()
        {
            //
            // string.Compareメソッドには、CultureInfoとCompareOptionsを
            // 引数にとるオーバーロードが定義されている。(他にもオーバーロードメソッドが存在します。)
            //
            // このオーバーロードを利用する際、CompareOptions.IgnoreKanaTypeを指定すると
            // 「ひらがな」と「カタカナ」の違いを無視して、文字列比較を行う事が出来る。
            //
            var ja1 = "はろーわーるど";
            var ja2 = "ハローワールド";

            var ci = new CultureInfo("ja-JP");

            // 標準の比較方法で比較
            Output.WriteLine("{0}", string.Compare(ja1, ja2, ci, CompareOptions.None).ToStringResult());
            // 大文字小文字を無視して比較.
            Output.WriteLine("{0}", string.Compare(ja1, ja2, ci, CompareOptions.IgnoreCase).ToStringResult());
            // ひらがなとカタカナの違いを無視して比較
            // つまり、「はろーわーるど」と「ハローワールド」を同じ文字列として比較
            Output.WriteLine("{0}", string.Compare(ja1, ja2, ci, CompareOptions.IgnoreKanaType).ToStringResult());

            //
            // string.Compareメソッドは、内部でCutureInfoから、そのカルチャーに紐づく
            // CompareInfoを取り出して、比較処理を行っているので、自前で直接CompareInfoを
            // 用意して、Compareメソッドを呼び出しても同じ結果となる。
            //
            var compInfo = CompareInfo.GetCompareInfo("ja-JP");

            Output.WriteLine("{0}", compInfo.Compare(ja1, ja2, CompareOptions.IgnoreKanaType).ToStringResult());
        }
예제 #4
0
        public void IsWellKnownOrdinalComparer_TestCases()
        {
            CompareInfo ci_enUS = CompareInfo.GetCompareInfo("en-US");

            // First, instantiate and test the comparers directly

            RunTest(null, false, false);
            RunTest(EqualityComparer <string> .Default, true, false);  // EC<string>.Default is Ordinal-equivalent
            RunTest(EqualityComparer <object> .Default, false, false); // EC<object>.Default isn't a string comparer
            RunTest(StringComparer.Ordinal, true, false);
            RunTest(StringComparer.OrdinalIgnoreCase, true, true);
            RunTest(StringComparer.InvariantCulture, false, false);                         // not ordinal
            RunTest(StringComparer.InvariantCultureIgnoreCase, false, false);               // not ordinal
            RunTest(GetNonRandomizedComparer("WrappedAroundDefaultComparer"), true, false); // EC<string>.Default is Ordinal-equivalent
            RunTest(GetNonRandomizedComparer("WrappedAroundStringComparerOrdinal"), true, false);
            RunTest(GetNonRandomizedComparer("WrappedAroundStringComparerOrdinalIgnoreCase"), true, true);
            RunTest(new CustomStringComparer(), false, false);                     // not an inbox comparer
            RunTest(ci_enUS.GetStringComparer(CompareOptions.None), false, false); // linguistic
            RunTest(ci_enUS.GetStringComparer(CompareOptions.Ordinal), true, false);
            RunTest(ci_enUS.GetStringComparer(CompareOptions.OrdinalIgnoreCase), true, true);

            // Then, make sure that this API works with common collection types

            RunTest(new Dictionary <string, object>().Comparer, true, false);
            RunTest(new Dictionary <string, object>(StringComparer.Ordinal).Comparer, true, false);
            RunTest(new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase).Comparer, true, true);
            RunTest(new Dictionary <string, object>(StringComparer.InvariantCulture).Comparer, false, false);
            RunTest(new Dictionary <string, object>(StringComparer.InvariantCultureIgnoreCase).Comparer, false, false);

            RunTest(new HashSet <string>().Comparer, true, false);
            RunTest(new HashSet <string>(StringComparer.Ordinal).Comparer, true, false);
            RunTest(new HashSet <string>(StringComparer.OrdinalIgnoreCase).Comparer, true, true);
            RunTest(new HashSet <string>(StringComparer.InvariantCulture).Comparer, false, false);
            RunTest(new HashSet <string>(StringComparer.InvariantCultureIgnoreCase).Comparer, false, false);
예제 #5
0
    public static void Go()
    {
        String output = String.Empty;

        String[]    symbol = new String[] { "<", "=", ">" };
        Int32       x;
        CultureInfo ci;

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

        // Sorting strings for French in France.
        ci      = new CultureInfo("fr-FR");
        x       = Math.Sign(ci.CompareInfo.Compare(s1, s2));
        output += String.Format("{0} Compare: {1} {3} {2}",
                                ci.Name, s1, s2, symbol[x + 1]);
        output += Environment.NewLine;

        // Sorting strings for Japanese in Japan.
        ci      = new CultureInfo("ja-JP");
        x       = Math.Sign(ci.CompareInfo.Compare(s1, s2));
        output += String.Format("{0} Compare: {1} {3} {2}",
                                ci.Name, s1, s2, symbol[x + 1]);
        output += Environment.NewLine;

        // Sorting strings for the thread's culture
        ci      = Thread.CurrentThread.CurrentCulture;
        x       = Math.Sign(ci.CompareInfo.Compare(s1, s2));
        output += String.Format("{0} Compare: {1} {3} {2}",
                                ci.Name, s1, s2, symbol[x + 1]);
        output += Environment.NewLine + Environment.NewLine;

        // The code below demonstrates how to use CompareInfo.Compare's
        // advanced options with 2 Japanese strings. One string represents
        // the word "shinkansen" (the name for the Japanese high-speed
        // train) in hiragana (one subtype of Japanese writing), and the
        // other represents the same word in katakana (another subtype of
        // Japanese writing).
        s1 = "しんかんせん"; // ("\u3057\u3093\u304B\u3093\u305b\u3093")
        s2 = "シンカンセン"; // ("\u30b7\u30f3\u30ab\u30f3\u30bb\u30f3")

        // Here is the result of a default comparison
        ci      = new CultureInfo("ja-JP");
        x       = Math.Sign(String.Compare(s1, s2, true, ci));
        output += String.Format("Simple {0} Compare: {1} {3} {2}",
                                ci.Name, s1, s2, symbol[x + 1]);
        output += Environment.NewLine;

        // Here is the result of a comparison that ignores
        // kana type (a type of Japanese writing)
        CompareInfo compareInfo = CompareInfo.GetCompareInfo("ja-JP");

        x       = Math.Sign(compareInfo.Compare(s1, s2, CompareOptions.IgnoreKanaType));
        output += String.Format("Advanced {0} Compare: {1} {3} {2}",
                                ci.Name, s1, s2, symbol[x + 1]);

        MessageBox.Show(output, "Comparing Strings For Sorting");
    }
예제 #6
0
        /**
         * Convenience override of getDisplayNames(ULocale, Comparator, string) that
         * uses the default collator for the locale as the comparator to
         * sort the display names, and null for the matchID.
         */
        public static IDictionary <string, string> GetDisplayNames(ICUService service, ULocale locale)
        {
            //Collator col;
            //try
            //{
            //    col = Collator.getInstance(locale.ToLocale());
            //}
            //catch (MissingResourceException e)
            //{
            //    // if no collator resources, we can't collate
            //    col = null;
            //}
            CompareInfo col;

            try
            {
                col = CompareInfo.GetCompareInfo(locale.ToLocale().ToString());
            }
            catch (MissingManifestResourceException e)
            {
                // if no collator resources, we can't collate
                col = null;
            }

            return(service.GetDisplayNames(locale, col, null));
        }
예제 #7
0
    public static void Main()
    {
        CompareInfo cmpi       = null;
        SortKey     sk1        = null;
        SortKey     sk2        = null;
        string      s          = "ABC";
        string      ignoreCase = "Ignore case";
        string      useCase    = "Use case   ";

// Get a CompareInfo object for the English-Great Britain culture.
        cmpi = CompareInfo.GetCompareInfo("en-GB");

// Get a sort key that ignores case for the specified string.
        sk1 = cmpi.GetSortKey(s, CompareOptions.IgnoreCase);
// Get a sort key with no compare option for the specified string.
        sk2 = cmpi.GetSortKey(s);

// Display the original string.
        Console.WriteLine("Original string: \"{0}\"", sk1.OriginalString);
        Console.WriteLine();

// Display the the string equivalent of the two sort keys.
        Console.WriteLine("CompareInfo (culture) name: {0}", cmpi.Name);
        Console.WriteLine("ToString - {0}: \"{1}\"", ignoreCase, sk1.ToString());
        Console.WriteLine("ToString - {0}: \"{1}\"", useCase, sk2.ToString());
        Console.WriteLine();

// Display the key data of the two sort keys.
        DisplayKeyData(sk1, ignoreCase);
        DisplayKeyData(sk2, useCase);
    }
예제 #8
0
        /**
         * Convenience override of getDisplayNames(ULocale, Comparator, string) that
         * uses the default collator for the locale as the comparator to
         * sort the display names, and null for the matchID.
         */
        public SortedDictionary <string, string> GetDisplayNames(ICUService service, ULocale locale)
        {
            //Collator col = Collator.getInstance(locale.toLocale());
            CompareInfo col = CompareInfo.GetCompareInfo(locale.ToLocale().Name);

            return(service.GetDisplayNames(locale, col, null));
        }
예제 #9
0
        private int LinearIndexOf(string fieldName, CompareOptions compareOptions)
        {
            CompareInfo compareInfo = _compareInfo;

            if (null == compareInfo)
            {
                if (-1 != _defaultLocaleID)
                {
                    compareInfo = CompareInfo.GetCompareInfo(_defaultLocaleID);
                }
                if (null == compareInfo)
                {
                    compareInfo = CultureInfo.InvariantCulture.CompareInfo;
                }
                _compareInfo = compareInfo;
            }
            int length = _fieldNames.Length;

            for (int i = 0; i < length; ++i)
            {
                if (0 == compareInfo.Compare(fieldName, _fieldNames[i], compareOptions))
                {
                    _fieldNameLookup[fieldName] = i; // add an exact match for the future
                    return(i);
                }
            }
            return(-1);
        }
예제 #10
0
    public static void Main()
    {
        // Creates and initializes an array of strings to sort.
        String[] myArr = new String[9] {
            "cant", "bill's", "coop", "cannot", "billet", "can't", "con", "bills", "co-op"
        };
        Console.WriteLine("\nInitially,");
        foreach (String myStr in myArr)
        {
            Console.WriteLine(myStr);
        }

        // Creates and initializes a Comparer to use.
        //CultureInfo myCI = new CultureInfo( "en-US", false );
        MyStringComparer myComp = new MyStringComparer(CompareInfo.GetCompareInfo("en-US"), CompareOptions.None);

        // Sorts the array without StringSort.
        Array.Sort(myArr, myComp);
        Console.WriteLine("\nAfter sorting without CompareOptions.StringSort:");
        foreach (String myStr in myArr)
        {
            Console.WriteLine(myStr);
        }

        // Sorts the array with StringSort.
        myComp = new MyStringComparer(CompareInfo.GetCompareInfo("en-US"), CompareOptions.StringSort);
        Array.Sort(myArr, myComp);
        Console.WriteLine("\nAfter sorting with CompareOptions.StringSort:");
        foreach (String myStr in myArr)
        {
            Console.WriteLine(myStr);
        }
    }
예제 #11
0
 public CharacterTest()
 {
     _MarvelPublicKey  = "67d146c4c462f0b55bf12bb7d60948af";
     _MarvelPrivateKey = "54fd1a8ac788767cc91938bcb96755186074970b";
     _Marvel           = new Marvel(_MarvelPublicKey, _MarvelPrivateKey);
     _Comparer         = CompareInfo.GetCompareInfo("en-US");
 }
예제 #12
0
            public int Compare(string a, string b)
            {
                //so sánh
                if (a == b)
                {
                    return(0);
                }
                if (a == null)
                {
                    return(-1);
                }
                if (b == null)
                {
                    return(1);
                }

                //kiểm tra a và b là string
                string sa = a as string;
                string sb = b as string;

                //
                var comparer = CompareInfo.GetCompareInfo("en-US");

                if (sa != null && sb != null)
                {
                    return(comparer.Compare(sa, sb, CompareOptions.Ordinal));
                }
                throw new ArgumentException("a và b phải là chuỗi");
            }
예제 #13
0
        /**
         * Convenience override of getDisplayNames(UCultureInfo, Comparator, string) that
         * uses the current default UCultureInfo as the locale, the default collator for
         * the locale as the comparator to sort the display names, and null for
         * the matchID.
         */
        public IDictionary <string, string> GetDisplayNames(ICUService service)
        {
            UCultureInfo locale = UCultureInfo.CurrentCulture;
            //Collator col = Collator.getInstance(locale.toLocale());
            CompareInfo col = CompareInfo.GetCompareInfo(locale.ToCultureInfo().Name);

            return(service.GetDisplayNames(locale, col, null));
        }
예제 #14
0
        public ComicTest()
        {
            _marvelPublicKey  = "ae9f4edf31b262cf13acb7b7f972bc61";
            _marvelPrivateKey = "ac741b4559b405ef585151ef6abe146c23e5d96a";

            _marvel   = new Marvel(_marvelPublicKey, _marvelPrivateKey);
            _comparer = CompareInfo.GetCompareInfo("en-US");
        }
예제 #15
0
 private CompareInfo GetCompareInfo()
 {
     if (_defaultLocaleID != -1)
     {
         return(CompareInfo.GetCompareInfo(_defaultLocaleID));
     }
     return(CultureInfo.InvariantCulture.CompareInfo);
 }
예제 #16
0
        public void TestCompareInfo()
        {
            CompareInfo ciENG = CompareInfo.GetCompareInfo("en-US");
            CompareInfo ciFR  = CompareInfo.GetCompareInfo("fr-FR");

            Assert.True(ciENG.Name.Equals("en-US", StringComparison.CurrentCultureIgnoreCase));
            Assert.NotEqual(ciENG.GetHashCode(), ciFR.GetHashCode());
            Assert.NotEqual(ciENG, ciFR);
        }
예제 #17
0
    public static void Compare(string localeName, string left, string right, int expected, CompareOptions options)
    {
        CompareInfo ci = CompareInfo.GetCompareInfo(localeName);

        Assert.Equal(expected, Math.Sign(ci.Compare(left, right, options)));

        if (options == CompareOptions.None)
        {
            Assert.Equal(expected, Math.Sign(ci.Compare(left, right)));
        }
    }
예제 #18
0
        public void SetCollation(string newName)
        {
            string name = NameToCSharpName[newName];

            if (name == null)
            {
                throw Error.GetError(0x157d, newName);
            }
            this._name.Rename(newName, true);
            this._locale  = CultureInfo.GetCultureInfo(name);
            this.Collator = CompareInfo.GetCompareInfo(name);
        }
예제 #19
0
    public static void EqualsAndHashCode()
    {
        CompareInfo ciInvariantFromCultureInfo = CultureInfo.InvariantCulture.CompareInfo;
        CompareInfo ciInvariantFromFactory     = CompareInfo.GetCompareInfo("");
        CompareInfo ciEnUs = CompareInfo.GetCompareInfo("en-US");

        Assert.True(ciInvariantFromCultureInfo.Equals(ciInvariantFromFactory));
        Assert.False(ciEnUs.Equals(ciInvariantFromCultureInfo));
        Assert.False(ciEnUs.Equals(new object()));

        Assert.Equal(ciInvariantFromCultureInfo.GetHashCode(), ciInvariantFromFactory.GetHashCode());
    }
예제 #20
0
        public static IEnumerable <object[]> Equals_TestData()
        {
            yield return(new object[] { CultureInfo.InvariantCulture.CompareInfo, CultureInfo.InvariantCulture.CompareInfo, true });

            yield return(new object[] { CultureInfo.InvariantCulture.CompareInfo, CompareInfo.GetCompareInfo(""), true });

            yield return(new object[] { new CultureInfo("en-US").CompareInfo, CompareInfo.GetCompareInfo("en-US"), true });

            yield return(new object[] { new CultureInfo("en-US").CompareInfo, CompareInfo.GetCompareInfo("fr-FR"), false });

            yield return(new object[] { new CultureInfo("en-US").CompareInfo, new object(), false });
        }
예제 #21
0
        //The compare info is specified by the server by specifying the default LocaleId.
        protected override CompareInfo GetCompareInfo()
        {
            CompareInfo?compareInfo = null;

            if (-1 != _defaultLocaleID)
            {
                compareInfo = CompareInfo.GetCompareInfo(_defaultLocaleID);
            }
            if (null == compareInfo)
            {
                compareInfo = base.GetCompareInfo();
            }
            return(compareInfo);
        }
        public static void ValidateLibraryResponse(Library library, PackageSpec expectedSpec)
        {
            Assert.AreEqual(expectedSpec.Id, library.Id);
            Assert.AreEqual(expectedSpec.Version.ToString(), library.Version);
            Assert.AreEqual(expectedSpec.Authors, library.Authors);
            Assert.AreEqual(expectedSpec.Title, library.Title);
            Assert.AreEqual(expectedSpec.Description, library.Description);

            // CRLF is mangled in the nuspec
            var cmp = CompareInfo.GetCompareInfo("en-US");

            Assert.AreEqual(0, cmp.Compare(expectedSpec.ReleaseNotes, library.ReleaseNotes, CompareOptions.IgnoreSymbols),
                            $"Release notes (ignoring symbols) don't match: {expectedSpec.ReleaseNotes} vs: {library.ReleaseNotes}");
        }
        internal static string EnumDisambiguate(string text, Type enumType)
        {
            string[] strArray2;
            string[] enumNames = enumType.GetEnumNames();
            CompareInfo.GetCompareInfo(CultureInfo.InvariantCulture.LCID);
            List <string> list = new List <string>();

            foreach (string str in enumNames)
            {
                if (str.StartsWith(text, StringComparison.OrdinalIgnoreCase))
                {
                    list.Add(str);
                }
            }
            if (list.Count == 0)
            {
                throw InterpreterError.NewInterpreterException(null, typeof(RuntimeException), null, "NoEnumNameMatch", EnumExpressionEvaluatorStrings.NoEnumNameMatch, new object[] { text, EnumAllValues(enumType) });
            }
            if (list.Count == 1)
            {
                return(list[0]);
            }
            foreach (string str2 in list)
            {
                if (str2.Equals(text, StringComparison.OrdinalIgnoreCase))
                {
                    return(str2);
                }
            }
            if (specialDisambiguateCases.TryGetValue(enumType, out strArray2))
            {
                foreach (string str3 in strArray2)
                {
                    if (str3.StartsWith(text, StringComparison.OrdinalIgnoreCase))
                    {
                        return(str3);
                    }
                }
            }
            StringBuilder builder = new StringBuilder(list[0]);
            string        str4    = ", ";

            for (int i = 1; i < list.Count; i++)
            {
                builder.Append(str4);
                builder.Append(list[i]);
            }
            throw InterpreterError.NewInterpreterException(null, typeof(RuntimeException), null, "MultipleEnumNameMatch", EnumExpressionEvaluatorStrings.MultipleEnumNameMatch, new object[] { text, builder.ToString() });
        }
예제 #24
0
        public void CompareTwoStrings()
        {
            String s1 = "hello";
            String s2 = "hella";

            Boolean eq;

            eq = String.Compare(s1, s2, StringComparison.Ordinal) == 0;

            CultureInfo ci          = new CultureInfo("de-De");
            CompareInfo compareInfo = CompareInfo.GetCompareInfo("es-ES");

            eq = compareInfo.Compare(s1, s2) == 0;
            eq = String.Compare(s1, s2, true, ci) == 0; //using culture info class, comparae with regional standarts
        }
예제 #25
0
    static void FindStringsWithSuffix_UsingCompareInfo(IEnumerable <string> strings, string suffix)
    {
        var ci = CompareInfo.GetCompareInfo("en-GB");

        output.Clear();
        profiler.Start();
        foreach (var s in strings)
        {
            if (ci.IsSuffix(s, suffix))
            {
                output.Add(s);
            }
        }
        profiler.Stop();
    }
예제 #26
0
        public void PreCmd_ParseCommand_OutputsExpressionContent()
        {
            string command = "2+2";

            MemoryStream memoryStream = new MemoryStream();
            Report       report       = new Report(new Session())
            {
                OutputStream = new StreamWriter(memoryStream)
            };
            CallScope callScope = new CallScope(report);

            callScope.PushBack(Value.StringValue(command));

            PreCmd.ParseCommand(callScope);

            report.OutputStream.Flush();
            memoryStream.Position = 0;
            string result = new StreamReader(memoryStream).ReadToEnd();

            string expected =
                @"--- Context is first posting of the following transaction ---
2004/05/27 Book Store
    ; This note applies to all postings. :SecondTag:
    Expenses:Books                 20 BOOK @ $10
    ; Metadata: Some Value
    ; Typed:: $100 + $200
    ; :ExampleTag:
    ; Here follows a note describing the posting.
    Liabilities:MasterCard        $-200.00

--- Input expression ---
2+2
--- Text as parsed ---
(2 + 2)
--- Expression tree ---
O_ADD (0)
 VALUE: 2 (0)
 VALUE: 2 (0)
--- Compiled tree ---
O_ADD (0)
 VALUE: 2 (0)
 VALUE: 2 (0)
--- Calculated value ---
{4}
";

            Assert.AreEqual(0, CompareInfo.GetCompareInfo(CultureInfo.CurrentCulture.LCID).Compare(expected, result, CompareOptions.IgnoreSymbols));
        }
예제 #27
0
        private void sortStrings()
        {
            String output = String.Empty;

            String[]    symbol = new String[] { "<", "=", ">" };
            Int32       x;
            CultureInfo ci;
            // Следующий код демонстрирует, насколько отличается результат
            // сравнения строк для различных региональных стандартов
            String s1 = "coté";
            String s2 = "côte";

            // Сортировка строк для французского языка (Франция)
            ci      = new CultureInfo("fr-FR");
            x       = Math.Sign(ci.CompareInfo.Compare(s1, s2));
            output += String.Format("{0} Compare: {1} {3} {2}", ci.Name, s1, s2, symbol[x + 1]);
            output += Environment.NewLine;
            // Сортировка строк для японского языка (Япония)
            ci      = new CultureInfo("ja-JP");
            x       = Math.Sign(ci.CompareInfo.Compare(s1, s2));
            output += String.Format("{0} Compare: {1} {3} {2}", ci.Name, s1, s2, symbol[x + 1]);
            output += Environment.NewLine;
            // Сортировка строк по региональным стандартам потока
            ci      = Thread.CurrentThread.CurrentCulture;
            x       = Math.Sign(ci.CompareInfo.Compare(s1, s2));
            output += String.Format("{0} Compare: {1} {3} {2}", ci.Name, s1, s2, symbol[x + 1]);
            output += Environment.NewLine + Environment.NewLine;
            // Следующий код демонстрирует использование дополнительных возможностей
            // метода CompareInfo.Compare при работе с двумя строками
            // на японском языке
            // Эти строки представляют слово "shinkansen" (название
            // высокоскоростного поезда) в разных вариантах письма:
            // хирагане и катакане
            s1 = " "; // ("\u3057\u3093\u304b\u3093\u305b\u3093")
            s2 = " "; // ("\u30b7\u30f3\u30ab\u30f3\u30bb\u30f3")
            // Результат сравнения по умолчанию
            ci      = new CultureInfo("ja-JP");
            x       = Math.Sign(String.Compare(s1, s2, true, ci));
            output += String.Format("Simple {0} Compare: {1} {3} {2}", ci.Name, s1, s2, symbol[x + 1]);
            output += Environment.NewLine;
            // Результат сравнения, который игнорирует тип каны
            CompareInfo compareInfo = CompareInfo.GetCompareInfo("ja-JP");

            x       = Math.Sign(compareInfo.Compare(s1, s2, CompareOptions.IgnoreKanaType));
            output += String.Format("Advanced {0} Compare: {1} {3} {2}", ci.Name, s1, s2, symbol[x + 1]);
            Console.WriteLine(output);
        }
예제 #28
0
        public static void LcidTest(string cultureName, int lcid)
        {
            var ci = CompareInfo.GetCompareInfo(lcid);

            Assert.Equal(cultureName, ci.Name);
            Assert.Equal(lcid, ci.LCID);

            Assembly assembly = typeof(string).Assembly;

            ci = CompareInfo.GetCompareInfo(lcid, assembly);
            Assert.Equal(cultureName, ci.Name);
            Assert.Equal(lcid, ci.LCID);

            ci = CompareInfo.GetCompareInfo(cultureName, assembly);
            Assert.Equal(cultureName, ci.Name);
            Assert.Equal(lcid, ci.LCID);
        }
예제 #29
0
        public int Compare(string x, string y)
        {
            if (x == y)
            {
                return(0);
            }
            if (x == null)
            {
                return(-1);
            }
            if (y == null)
            {
                return(1);
            }
            var vnpCompare = CompareInfo.GetCompareInfo("en-US");

            return(vnpCompare.Compare(x, y, CompareOptions.Ordinal));
        }
예제 #30
0
    public static void Main()
    {
        // Defines the strings to compare.
        String myStr1 = "calle";
        String myStr2 = "calor";

        // Uses GetCompareInfo to create the CompareInfo that uses the "es-ES" culture with international sort.
        CompareInfo myCompIntl = CompareInfo.GetCompareInfo("es-ES");

        // Uses GetCompareInfo to create the CompareInfo that uses the "es-ES" culture with traditional sort.
        CompareInfo myCompTrad = CompareInfo.GetCompareInfo(0x040A);

        // Uses the CompareInfo property of the InvariantCulture.
        CompareInfo myCompInva = CultureInfo.InvariantCulture.CompareInfo;

        // Compares two strings using myCompIntl.
        Console.WriteLine("Comparing \"{0}\" and \"{1}\"", myStr1, myStr2);
        Console.WriteLine("   With myCompIntl.Compare: {0}", myCompIntl.Compare(myStr1, myStr2));
        Console.WriteLine("   With myCompTrad.Compare: {0}", myCompTrad.Compare(myStr1, myStr2));
        Console.WriteLine("   With myCompInva.Compare: {0}", myCompInva.Compare(myStr1, myStr2));
    }