From: gu.martinm@gmail.com Date: Wed, 26 Mar 2014 19:09:01 +0000 (+0100) Subject: C# trying out Collation X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=dd82e53c82003ce6f1ef03e2cf96f95d2a81b697;p=CSharpForFun%2F.git C# trying out Collation --- diff --git a/Allgemeines/Collation/Collation.csproj b/Allgemeines/Collation/Collation.csproj new file mode 100644 index 0000000..077445a --- /dev/null +++ b/Allgemeines/Collation/Collation.csproj @@ -0,0 +1,43 @@ + + + + Debug + x86 + 10.0.0 + 2.0 + {85DE1B80-0DFF-4B75-A84C-91BF5E5DAAF0} + Exe + Collation + Collation + Collation with Mono and C# + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + true + x86 + + + full + true + bin\Release + prompt + 4 + true + x86 + + + + + + + + + + \ No newline at end of file diff --git a/Allgemeines/Collation/Collation.sln b/Allgemeines/Collation/Collation.sln new file mode 100644 index 0000000..d2fc79d --- /dev/null +++ b/Allgemeines/Collation/Collation.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Collation", "Collation.csproj", "{85DE1B80-0DFF-4B75-A84C-91BF5E5DAAF0}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x86 = Debug|x86 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {85DE1B80-0DFF-4B75-A84C-91BF5E5DAAF0}.Debug|x86.ActiveCfg = Debug|x86 + {85DE1B80-0DFF-4B75-A84C-91BF5E5DAAF0}.Debug|x86.Build.0 = Debug|x86 + {85DE1B80-0DFF-4B75-A84C-91BF5E5DAAF0}.Release|x86.ActiveCfg = Release|x86 + {85DE1B80-0DFF-4B75-A84C-91BF5E5DAAF0}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(MonoDevelopProperties) = preSolution + StartupItem = Collation.csproj + EndGlobalSection +EndGlobal diff --git a/Allgemeines/Collation/Program.cs b/Allgemeines/Collation/Program.cs new file mode 100644 index 0000000..ee6eeb3 --- /dev/null +++ b/Allgemeines/Collation/Program.cs @@ -0,0 +1,76 @@ +using System; +using System.Globalization; +using System.Collections; + +namespace Collation +{ + class MainClass + { + public static void Main (string[] args) + { + string string1 = "hello gus"; + string string2 = "HELLO GUS"; + int compareResult = 0; + + // Like Java String.compareTo (without culture, + // using unicode values directly) + compareResult = String.Compare(string1, string2, + StringComparison.Ordinal); + Console.WriteLine("{0} comparison of '{1}' and '{2}': {3}", + StringComparison.Ordinal, string1, string2, + compareResult); + + // Like Java String.compareToIgnoreCase (without culture, + // using unicode values directly) + compareResult = String.Compare(string1, string2, + StringComparison.OrdinalIgnoreCase); + Console.WriteLine("{0} comparison of '{1}' and '{2}': {3}", + StringComparison.OrdinalIgnoreCase, string1, string2, + compareResult); + + // Like Java String.toLowerCase(Locale.ENGLISH) + string key = "HELLO GUS"; + string lowerKey = key.ToLower (CultureInfo.InvariantCulture); + Console.WriteLine ("Key: {0}", lowerKey); + + string[] words = {"cote", "coté", "côte", "côté"}; + + // C# unlike Java does not implement Levels/Strengths collation configurations. + // It always uses the five levels, see: Mono.Globalization.Unicode/SimpleCollator.cs + + // InvariantCulture: English like Java: Locale.ENGLISH + Array.Sort (words, StringComparer.InvariantCulture); + Console.WriteLine("Words list Invariant: "); + printValues (words); + + // without culture, using unicode values directly + Array.Sort (words, StringComparer.Ordinal); + Console.WriteLine("Words list Ordinal: "); + printValues (words); + + // like Java new Locale("es","ES") + CultureInfo cultureES = CultureInfo.CreateSpecificCulture ("es-ES"); + IComparer cultureComparerES =new CaseInsensitiveComparer (cultureES); + Array.Sort (words, cultureComparerES); + Console.WriteLine("Words list ES: "); + printValues (words); + + CultureInfo cultureFR = CultureInfo.CreateSpecificCulture ("fr-FR"); + IComparer cultureComparerFR =new CaseInsensitiveComparer (cultureFR); + Array.Sort (words, cultureComparerFR); + Console.WriteLine("Words list FR: "); + printValues (words); + + } + + private static void printValues(string[] words) + { + foreach (var word in words) + { + Console.Write ("{0} ", word); + } + + Console.WriteLine (); + } + } +} diff --git a/Allgemeines/Collation/Properties/AssemblyInfo.cs b/Allgemeines/Collation/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..e638937 --- /dev/null +++ b/Allgemeines/Collation/Properties/AssemblyInfo.cs @@ -0,0 +1,22 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. +[assembly: AssemblyTitle ("Collation")] +[assembly: AssemblyDescription ("")] +[assembly: AssemblyConfiguration ("")] +[assembly: AssemblyCompany ("")] +[assembly: AssemblyProduct ("")] +[assembly: AssemblyCopyright ("gmm003es")] +[assembly: AssemblyTrademark ("")] +[assembly: AssemblyCulture ("")] +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. +[assembly: AssemblyVersion ("1.0.*")] +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] +