From 9b8668273ad28220c14089ab5b9d09156b7a0bb2 Mon Sep 17 00:00:00 2001 From: Dave Rayment Date: Mon, 1 Jul 2024 16:24:50 +0100 Subject: [PATCH 01/16] Update compareoptions_stringsort.cs StringSort example updated with note about changes in .NET 5 and later versions. Now uses more modern and idiomatic C# language features, and correct formatting. --- .../Overview/compareoptions_stringsort.cs | 104 ++++++++---------- 1 file changed, 44 insertions(+), 60 deletions(-) diff --git a/snippets/csharp/System.Globalization/CompareOptions/Overview/compareoptions_stringsort.cs b/snippets/csharp/System.Globalization/CompareOptions/Overview/compareoptions_stringsort.cs index b8fc19680cf..65efc20e8ce 100644 --- a/snippets/csharp/System.Globalization/CompareOptions/Overview/compareoptions_stringsort.cs +++ b/snippets/csharp/System.Globalization/CompareOptions/Overview/compareoptions_stringsort.cs @@ -1,67 +1,52 @@ -// The following code example shows how sorting with CompareOptions.StringSort differs from sorting without CompareOptions.StringSort. - -// +// using System; -using System.Collections; +using System.Collections.Generic; using System.Globalization; -public class SamplesCompareOptions { - - private class MyStringComparer: IComparer { - private CompareInfo myComp; - private CompareOptions myOptions = CompareOptions.None; - - // Constructs a comparer using the specified CompareOptions. - public MyStringComparer( CompareInfo cmpi, CompareOptions options ) { - myComp = cmpi; - this.myOptions = options; - } - - // Compares strings with the CompareOptions specified in the constructor. - public int Compare(Object a, Object b) { - if (a == b) return 0; - if (a == null) return -1; - if (b == null) return 1; - - String sa = a as String; - String sb = b as String; - if (sa != null && sb != null) - return myComp.Compare(sa, sb, myOptions); - throw new ArgumentException("a and b should be strings."); - } - } - - 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 ); - } +public class StringSort +{ + public static void Main() + { + var wordList = new List + { + "cant", "bill's", "coop", "cannot", "billet", "can't", "con", "bills", "co-op" + }; + + Console.WriteLine("Before sorting:"); + foreach (string word in wordList) + { + Console.WriteLine(word); + } + + Console.WriteLine(Environment.NewLine + "After sorting with CompareOptions.None:"); + SortAndDisplay(wordList, CompareOptions.None); + + Console.WriteLine(Environment.NewLine + "After sorting with CompareOptions.StringSort:"); + SortAndDisplay(wordList, CompareOptions.StringSort); + } + + // Sort the list of words with the supplied CompareOptions. + private static void SortAndDisplay(List unsorted, CompareOptions options) + { + // Create a copy of the original list to sort. + var words = new List(unsorted); + // Define the CompareInfo to use to compare strings. + var comparer = CultureInfo.InvariantCulture.CompareInfo; + + // Sort the copy with the supplied CompareOptions then display. + words.Sort((str1, str2) => comparer.Compare(str1, str2, options)); + foreach (string word in words) + { + Console.WriteLine(word); + } + } } /* -This code produces the following output. +CompareOptions.None and CompareOptions.StringSort provide identical ordering by default +in .NET 5 and later, but in prior versions, the output will be the following: -Initially, +Before sorting: cant bill's coop @@ -72,7 +57,7 @@ This code produces the following output. bills co-op -After sorting without CompareOptions.StringSort: +After sorting with CompareOptions.None: billet bills bill's @@ -93,6 +78,5 @@ This code produces the following output. co-op con coop - */ -// +// From 5689fbf85fd8126e27299f2e822cf0bcd6fcd74b Mon Sep 17 00:00:00 2001 From: Dave Rayment Date: Fri, 5 Jul 2024 13:10:35 +0100 Subject: [PATCH 02/16] Add files via upload New CompareOptions example showing each option. --- .../Overview/compareoptions_values.cs | 100 ++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 snippets/csharp/System.Globalization/CompareOptions/Overview/compareoptions_values.cs diff --git a/snippets/csharp/System.Globalization/CompareOptions/Overview/compareoptions_values.cs b/snippets/csharp/System.Globalization/CompareOptions/Overview/compareoptions_values.cs new file mode 100644 index 00000000000..99927dd7f5f --- /dev/null +++ b/snippets/csharp/System.Globalization/CompareOptions/Overview/compareoptions_values.cs @@ -0,0 +1,100 @@ +// +using System; +using System.Globalization; + +public class CompareOptionsExample +{ + public static void Main() + { + // Uppercase and lowercase characters are equivalent (according to the culture rules) + // when IgnoreCase is used. + TestStringEquality("ONE two", "one TWO", "Case sensitivity", CompareOptions.IgnoreCase); + + // Punctuation is ignored with the IgnoreSymbols option. + TestStringEquality("hello world", "hello, world!", "Punctuation", CompareOptions.IgnoreSymbols); + + // Whitespace and mathematical symbols are also ignored with IgnoreSymbols. + TestStringEquality("3 + 5 = 8", "358", "Whitespace and mathematical symbols", CompareOptions.IgnoreSymbols); + + // Caution: currency symbols and thousands separators are ignored with IgnoreSymbols. + // Parse strings containing numbers/currency and compare them numerically instead. + TestStringEquality("Total $15,000", "Total: £150.00", "Currency symbols, decimals and thousands separators", CompareOptions.IgnoreSymbols); + + // Full width characters are common in East Asian languages. Use the IgnoreWidth + // option to treat full- and half-width characters as equal. + TestStringEquality("abc,-", "abc,-", "Half width and full width characters", CompareOptions.IgnoreWidth); + + // The same string in Hiragana and Katakana is equal when IgnoreKanaType is used. + TestStringEquality("ありがとう", "アリガトウ", "Hiragana and Katakana strings", CompareOptions.IgnoreKanaType); + + // When comparing with the IgnoreNonSpace option, characters like diacritical marks are ignored. + TestStringEquality("café", "cafe", "Diacritical marks", CompareOptions.IgnoreNonSpace); + + // Ligature characters and their non-ligature forms compare equal with the IgnoreNonSpace option. + // Note: prior to .NET 5, ligature characters were equal to their expanded forms by default. + TestStringEquality("straße œuvre cæsar", "strasse oeuvre caesar", "Ligature characters", CompareOptions.IgnoreNonSpace); + } + + private static void TestStringEquality(string str1, string str2, string description, CompareOptions options) + { + Console.WriteLine(Environment.NewLine + description + ":"); + // First test with the default CompareOptions then with the provided options + TestStringEquality(str1, str2, CompareOptions.None); + TestStringEquality(str1, str2, options); + } + + private static void TestStringEquality(string str1, string str2, CompareOptions options) + { + Console.Write($" When using CompareOptions.{options}, \"{str1}\" and \"{str2}\" are "); + if (string.Compare(str1, str2, CultureInfo.InvariantCulture, options) != 0) + { + Console.Write("not "); + } + Console.WriteLine("equal."); + } +} + +/* +In .NET 5 and later, the output will be the following: + +Case sensitivity: + When using CompareOptions.None, "ONE two" and "one TWO" are not equal. + When using CompareOptions.IgnoreCase, "ONE two" and "one TWO" are equal. + +Punctuation: + When using CompareOptions.None, "hello world" and "hello, world!" are not equal. + When using CompareOptions.IgnoreSymbols, "hello world" and "hello, world!" are equal. + +Whitespace and mathematical symbols: + When using CompareOptions.None, "3 + 5 = 8" and "358" are not equal. + When using CompareOptions.IgnoreSymbols, "3 + 5 = 8" and "358" are equal. + +Currency symbols, decimals and thousands separators: + When using CompareOptions.None, "Total $15,000" and "Total: £150.00" are not equal. + When using CompareOptions.IgnoreSymbols, "Total $15,000" and "Total: £150.00" are equal. + +Half width and full width characters: + When using CompareOptions.None, "abc,-" and "abc,-" are not equal. + When using CompareOptions.IgnoreWidth, "abc,-" and "abc,-" are equal. + +Hiragana and Katakana strings: + When using CompareOptions.None, "ありがとう" and "アリガトウ" are not equal. + When using CompareOptions.IgnoreKanaType, "ありがとう" and "アリガトウ" are equal. + +Diacritical marks: + When using CompareOptions.None, "café" and "cafe" are not equal. + When using CompareOptions.IgnoreNonSpace, "café" and "cafe" are equal. + +Ligature characters: + When using CompareOptions.None, "straße œuvre cæsar" and "strasse oeuvre caesar" are not equal. + When using CompareOptions.IgnoreNonSpace, "straße œuvre cæsar" and "strasse oeuvre caesar" are equal. + + +Note: when using .NET versions prior to .NET 5, ligature characters compare as equal to their +non-ligature counterparts by default, so the last test will output as follows: + +Ligature characters: + When using CompareOptions.None, "straße œuvre cæsar" and "strasse oeuvre caesar" are equal. + When using CompareOptions.IgnoreNonSpace, "straße œuvre cæsar" and "strasse oeuvre caesar" are equal. +*/ +// \ No newline at end of file From fc8904615c81e1d5905046c668efaed6b6a26cdd Mon Sep 17 00:00:00 2001 From: Dave Rayment Date: Fri, 5 Jul 2024 13:17:13 +0100 Subject: [PATCH 03/16] Create compareoptions_stringsort.fs --- .../compareoptions_stringsort.fs | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 snippets/fsharp/System.Globalization/compareoptions_stringsort.fs diff --git a/snippets/fsharp/System.Globalization/compareoptions_stringsort.fs b/snippets/fsharp/System.Globalization/compareoptions_stringsort.fs new file mode 100644 index 00000000000..b47864e0755 --- /dev/null +++ b/snippets/fsharp/System.Globalization/compareoptions_stringsort.fs @@ -0,0 +1,67 @@ +// +open System +open System.Collections.Generic +open System.Globalization + +let sortAndDisplay (unsorted: List) (options: CompareOptions) = + let words = new List(unsorted) + let comparer = CultureInfo.InvariantCulture.CompareInfo + words.Sort((fun str1 str2 -> comparer.Compare(str1, str2, options))) + for word in words do + printfn "%s" word + +[] +let main argv = + let wordList = new List( + ["cant"; "bill's"; "coop"; "cannot"; "billet"; "can't"; "con"; "bills"; "co-op"]) + + printfn "Before sorting:" + for word in wordList do + printfn "%s" word + + printfn "\nAfter sorting with CompareOptions.None:" + sortAndDisplay wordList CompareOptions.None + + printfn "\nAfter sorting with CompareOptions.StringSort:" + sortAndDisplay wordList CompareOptions.StringSort + + 0 // return an integer exit code + +(* +CompareOptions.None and CompareOptions.StringSort provide identical ordering by default +in .NET 5 and later, but in prior versions, the output will be the following: + +Before sorting: +cant +bill's +coop +cannot +billet +can't +con +bills +co-op + +After sorting with CompareOptions.None: +billet +bills +bill's +cannot +cant +can't +con +coop +co-op + +After sorting with CompareOptions.StringSort: +bill's +billet +bills +can't +cannot +cant +co-op +con +coop +*) +// From ca78dfd17e7fafdaa8f4b0c181bc20cff5ff646d Mon Sep 17 00:00:00 2001 From: Dave Rayment Date: Fri, 5 Jul 2024 13:22:02 +0100 Subject: [PATCH 04/16] Add files via upload F# example showing usage of each CompareOptions value. --- .../compareoptions_values.fs | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 snippets/fsharp/System.Globalization/compareoptions_values.fs diff --git a/snippets/fsharp/System.Globalization/compareoptions_values.fs b/snippets/fsharp/System.Globalization/compareoptions_values.fs new file mode 100644 index 00000000000..d80b46ca732 --- /dev/null +++ b/snippets/fsharp/System.Globalization/compareoptions_values.fs @@ -0,0 +1,90 @@ +// +open System +open System.Globalization + +let testStringEquality (str1: string) (str2: string) (description: string) (options: CompareOptions) = + printfn "\n%s:" description + + let compareAndPrint opts = + let result = String.Compare(str1, str2, CultureInfo.InvariantCulture, opts) + let equalityStatus = if result = 0 then "equal" else "not equal" + printfn " When using CompareOptions.%A, \"%s\" and \"%s\" are %s." opts str1 str2 equalityStatus + + compareAndPrint CompareOptions.None + compareAndPrint options + +[] +let main argv = + // Uppercase and lowercase characters are equivalent (according to the culture rules) when IgnoreCase is used. + testStringEquality "ONE two" "one TWO" "Case sensitivity" CompareOptions.IgnoreCase + + // Punctuation is ignored with the IgnoreSymbols option. + testStringEquality "hello world" "hello, world!" "Punctuation" CompareOptions.IgnoreSymbols + + // Whitespace and mathematical symbols are also ignored with IgnoreSymbols. + testStringEquality "3 + 5 = 8" "358" "Whitespace and mathematical symbols" CompareOptions.IgnoreSymbols + + // Caution: currency symbols and thousands separators are ignored with IgnoreSymbols. + // Parse strings containing numbers/currency and compare them numerically instead. + testStringEquality "Total $15,000" "Total: £150.00" "Currency symbols, decimals and thousands separators" CompareOptions.IgnoreSymbols + + // Full width characters are common in East Asian languages. Use the IgnoreWidth + // option to treat full- and half-width characters as equal. + testStringEquality "abc,-" "abc,-" "Half width and full width characters" CompareOptions.IgnoreWidth + + // The same string in Hiragana and Katakana is equal when IgnoreKanaType is used. + testStringEquality "ありがとう" "アリガトウ" "Hiragana and Katakana strings" CompareOptions.IgnoreKanaType + + // When comparing with the IgnoreNonSpace option, characters like diacritical marks are ignored. + testStringEquality "café" "cafe" "Diacritical marks" CompareOptions.IgnoreNonSpace + + // Ligature characters and their non-ligature forms compare equal with the IgnoreNonSpace option. + // Note: prior to .NET 5, ligature characters were equal to their expanded forms by default. + testStringEquality "straße œuvre cæsar" "strasse oeuvre caesar" "Ligature characters" CompareOptions.IgnoreNonSpace + + 0 // return an integer exit code + +(* +In .NET 5 and later, the output will be the following: + +Case sensitivity: + When using CompareOptions.None, "ONE two" and "one TWO" are not equal. + When using CompareOptions.IgnoreCase, "ONE two" and "one TWO" are equal. + +Punctuation: + When using CompareOptions.None, "hello world" and "hello, world!" are not equal. + When using CompareOptions.IgnoreSymbols, "hello world" and "hello, world!" are equal. + +Whitespace and mathematical symbols: + When using CompareOptions.None, "3 + 5 = 8" and "358" are not equal. + When using CompareOptions.IgnoreSymbols, "3 + 5 = 8" and "358" are equal. + +Currency symbols, decimals and thousands separators: + When using CompareOptions.None, "Total $15,000" and "Total: £150.00" are not equal. + When using CompareOptions.IgnoreSymbols, "Total $15,000" and "Total: £150.00" are equal. + +Half width and full width characters: + When using CompareOptions.None, "abc,-" and "abc,-" are not equal. + When using CompareOptions.IgnoreWidth, "abc,-" and "abc,-" are equal. + +Hiragana and Katakana strings: + When using CompareOptions.None, "ありがとう" and "アリガトウ" are not equal. + When using CompareOptions.IgnoreKanaType, "ありがとう" and "アリガトウ" are equal. + +Diacritical marks: + When using CompareOptions.None, "café" and "cafe" are not equal. + When using CompareOptions.IgnoreNonSpace, "café" and "cafe" are equal. + +Ligature characters: + When using CompareOptions.None, "straße œuvre cæsar" and "strasse oeuvre caesar" are not equal. + When using CompareOptions.IgnoreNonSpace, "straße œuvre cæsar" and "strasse oeuvre caesar" are equal. + + +Note: when using .NET versions prior to .NET 5, ligature characters compare as equal to their +non-ligature counterparts by default, so the last test will output as follows: + +Ligature characters: + When using CompareOptions.None, "straße œuvre cæsar" and "strasse oeuvre caesar" are equal. + When using CompareOptions.IgnoreNonSpace, "straße œuvre cæsar" and "strasse oeuvre caesar" are equal. +*) +// \ No newline at end of file From da5bd851486385fafbfc3014711f24b64b63aaf1 Mon Sep 17 00:00:00 2001 From: Dave Rayment Date: Fri, 5 Jul 2024 13:33:19 +0100 Subject: [PATCH 05/16] Update compareoptions_stringsort.vb Rewritten. Uses more modern language constructs. Includes note about differences between .NET 5+ and earlier versions. --- .../VB/compareoptions_stringsort.vb | 114 ++++++------------ 1 file changed, 37 insertions(+), 77 deletions(-) diff --git a/snippets/visualbasic/VS_Snippets_CLR_System/system.Globalization.CompareOptions.StringSort/VB/compareoptions_stringsort.vb b/snippets/visualbasic/VS_Snippets_CLR_System/system.Globalization.CompareOptions.StringSort/VB/compareoptions_stringsort.vb index da1c2c9195e..5e8e0feed0a 100644 --- a/snippets/visualbasic/VS_Snippets_CLR_System/system.Globalization.CompareOptions.StringSort/VB/compareoptions_stringsort.vb +++ b/snippets/visualbasic/VS_Snippets_CLR_System/system.Globalization.CompareOptions.StringSort/VB/compareoptions_stringsort.vb @@ -1,87 +1,47 @@ -' The following code example shows how sorting with CompareOptions.StringSort differs from sorting without CompareOptions.StringSort. - -' -Imports System.Collections +'// +Imports System +Imports System.Collections.Generic Imports System.Globalization -Public Class SamplesCompareOptions - - Private Class MyStringComparer - Implements IComparer - - Private myComp As CompareInfo - Private myOptions As CompareOptions = CompareOptions.None - - ' Constructs a comparer using the specified CompareOptions. - Public Sub New(cmpi As CompareInfo, options As CompareOptions) - myComp = cmpi - Me.myOptions = options - End Sub - - ' Compares strings with the CompareOptions specified in the constructor. - Public Function Compare(a As [Object], b As [Object]) As Integer Implements IComparer.Compare - If a = b Then - Return 0 - End If - If a Is Nothing Then - Return - 1 - End If - If b Is Nothing Then - Return 1 - End If - - Dim sa As [String] = a - Dim sb As [String] = b - If Not (sa Is Nothing) And Not (sb Is Nothing) Then - Return myComp.Compare(sa, sb, myOptions) - End If - Throw New ArgumentException("a and b should be strings.") - - End Function 'Compare +Public Class StringSort + Public Shared Sub Main() + Dim wordList As New List(Of String) From { + "cant", "bill's", "coop", "cannot", "billet", "can't", "con", "bills", "co-op" + } - End Class + Console.WriteLine("Before sorting:") + For Each word In wordList + Console.WriteLine(word) + Next + Console.WriteLine(Environment.NewLine & "After sorting with CompareOptions.None:") + SortAndDisplay(wordList, CompareOptions.None) - Public Shared Sub Main() - - ' Creates and initializes an array of strings to sort. - Dim myArr() As [String] = {"cant", "bill's", "coop", "cannot", "billet", "can't", "con", "bills", "co-op"} - Console.WriteLine() - Console.WriteLine("Initially,") - Dim myStr As [String] - For Each myStr In myArr - Console.WriteLine(myStr) - Next myStr + Console.WriteLine(Environment.NewLine & "After sorting with CompareOptions.StringSort:") + SortAndDisplay(wordList, CompareOptions.StringSort) + End Sub - ' Creates and initializes a Comparer to use. - 'CultureInfo myCI = new CultureInfo( "en-US", false ); - Dim myComp As New MyStringComparer(CompareInfo.GetCompareInfo("en-US"), CompareOptions.None) - - ' Sorts the array without StringSort. - Array.Sort(myArr, myComp) - Console.WriteLine() - Console.WriteLine("After sorting without CompareOptions.StringSort:") - For Each myStr In myArr - Console.WriteLine(myStr) - Next myStr + ' Sort the list of words with the supplied CompareOptions. + Private Shared Sub SortAndDisplay(unsorted As List(Of String), options As CompareOptions) + ' Create a copy of the original list to sort. + Dim words As New List(Of String)(unsorted) - ' Sorts the array with StringSort. - myComp = New MyStringComparer(CompareInfo.GetCompareInfo("en-US"), CompareOptions.StringSort) - Array.Sort(myArr, myComp) - Console.WriteLine() - Console.WriteLine("After sorting with CompareOptions.StringSort:") - For Each myStr In myArr - Console.WriteLine(myStr) - Next myStr + ' Define the CompareInfo to use to compare strings. + Dim comparer As CompareInfo = CultureInfo.InvariantCulture.CompareInfo - End Sub + ' Sort the copy with the supplied CompareOptions then display. + words.Sort(Function(str1, str2) comparer.Compare(str1, str2, options)) + For Each word In words + Console.WriteLine(word) + Next + End Sub End Class - -'This code produces the following output. +' CompareOptions.None and CompareOptions.StringSort provide identical ordering by default +' in .NET 5 And later, but in prior versions, the output will be the following: ' -'Initially, +'Before sorting 'cant 'bill's 'coop @@ -91,8 +51,8 @@ End Class 'con 'bills 'co-op -' -'After sorting without CompareOptions.StringSort: + +'After sorting with CompareOptions.None 'billet 'bills 'bill's @@ -102,8 +62,8 @@ End Class 'con 'coop 'co-op -' -'After sorting with CompareOptions.StringSort: + +'After sorting with CompareOptions.StringSort 'bill's 'billet 'bills @@ -114,4 +74,4 @@ End Class 'con 'coop -' \ No newline at end of file +'// From 8103253fb6270c3fa647801f03fea5bbd75dac74 Mon Sep 17 00:00:00 2001 From: Dave Rayment Date: Fri, 5 Jul 2024 13:43:15 +0100 Subject: [PATCH 06/16] Update compareoptions_stringsort.cpp Rewritten with more modern .NET language usage, and note about difference between .NET 5+ and prior versions with regard to sort order. --- .../CPP/compareoptions_stringsort.cpp | 115 +++++++----------- 1 file changed, 45 insertions(+), 70 deletions(-) diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Globalization.CompareOptions.StringSort/CPP/compareoptions_stringsort.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Globalization.CompareOptions.StringSort/CPP/compareoptions_stringsort.cpp index 5885be28f72..02d0766c4fe 100644 --- a/snippets/cpp/VS_Snippets_CLR_System/system.Globalization.CompareOptions.StringSort/CPP/compareoptions_stringsort.cpp +++ b/snippets/cpp/VS_Snippets_CLR_System/system.Globalization.CompareOptions.StringSort/CPP/compareoptions_stringsort.cpp @@ -1,89 +1,64 @@ +// +#include +#using -// The following code example shows how sorting with CompareOptions::StringSort differs -// from sorting with->Item[Out] CompareOptions::StringSort. -// using namespace System; -using namespace System::Collections; +using namespace System::Collections::Generic; using namespace System::Globalization; -// __gc public class SamplesCompareOptions { -ref class MyStringComparer: public IComparer +ref class StringSort { public: + static void Main() + { + auto wordList = gcnew List { + "cant", "bill's", "coop", "cannot", "billet", "can't", "con", "bills", "co-op" + }; - // Constructs a comparer using the specified CompareOptions. - CompareInfo^ myComp; - CompareOptions myOptions; - MyStringComparer( CompareInfo^ cmpi, CompareOptions options ) - : myComp( cmpi ), myOptions( options ) - {} + Console::WriteLine("Before sorting:"); + for each (String^ word in wordList) + { + Console::WriteLine(word); + } - // Compares strings with the CompareOptions specified in the constructor. - virtual int Compare( Object^ a, Object^ b ) - { - if ( a == b ) - return 0; + Console::WriteLine(Environment::NewLine + "After sorting with CompareOptions::None:"); + SortAndDisplay(wordList, CompareOptions::None); - if ( a == nullptr ) - return -1; + Console::WriteLine(Environment::NewLine + "After sorting with CompareOptions::StringSort:"); + SortAndDisplay(wordList, CompareOptions::StringSort); + } - if ( b == nullptr ) - return 1; +private: + static void SortAndDisplay(List^ unsorted, CompareOptions options) + { + // Create a copy of the original list to sort. + auto words = gcnew List(unsorted); + // Define the CompareInfo to use to compare strings. + CompareInfo^ comparer = CultureInfo::InvariantCulture->CompareInfo; - String^ sa = dynamic_cast(a); - String^ sb = dynamic_cast(b); - if ( sa != nullptr && sb != nullptr ) - return myComp->Compare( sa, sb, myOptions ); + // Sort the copy with the supplied CompareOptions then display. + words->Sort(gcnew Comparison([comparer, options](String^ str1, String^ str2) { + return comparer->Compare(str1, str2, options); + })); - throw gcnew ArgumentException( "a and b should be strings." ); - } + for each (String^ word in words) + { + Console::WriteLine(word); + } + } }; -int main() +int main(array ^args) { - - // Creates and initializes an array of strings to sort. - array^myArr = {"cant","bill's","coop","cannot","billet","can't","con","bills","co-op"}; - Console::WriteLine( "\nInitially, " ); - IEnumerator^ myEnum = myArr->GetEnumerator(); - while ( myEnum->MoveNext() ) - { - String^ myStr = safe_cast(myEnum->Current); - Console::WriteLine( myStr ); - } - - - // Creates and initializes a Comparer to use. - //CultureInfo* myCI = new CultureInfo(S"en-US", false); - MyStringComparer^ myComp = gcnew MyStringComparer( CompareInfo::GetCompareInfo( "en-US" ),CompareOptions::None ); - - // Sorts the array without StringSort. - Array::Sort( myArr, myComp ); - Console::WriteLine( "\nAfter sorting without CompareOptions::StringSort:" ); - myEnum = myArr->GetEnumerator(); - while ( myEnum->MoveNext() ) - { - String^ myStr = safe_cast(myEnum->Current); - Console::WriteLine( myStr ); - } - - - // Sorts the array with StringSort. - myComp = gcnew MyStringComparer( CompareInfo::GetCompareInfo( "en-US" ),CompareOptions::StringSort ); - Array::Sort( myArr, myComp ); - Console::WriteLine( "\nAfter sorting with CompareOptions::StringSort:" ); - myEnum = myArr->GetEnumerator(); - while ( myEnum->MoveNext() ) - { - String^ myStr = safe_cast(myEnum->Current); - Console::WriteLine( myStr ); - } + StringSort::Main(); + return 0; } /* -This code produces the following output. +CompareOptions.None and CompareOptions.StringSort provide identical ordering by default +in .NET 5 and later, but in prior versions, the output will be the following: -Initially, +Before sorting: cant bill's coop @@ -94,7 +69,7 @@ con bills co-op -After sorting without CompareOptions::StringSort: +After sorting with CompareOptions.None: billet bills bill's @@ -105,7 +80,7 @@ con coop co-op -After sorting with CompareOptions::StringSort: +After sorting with CompareOptions.StringSort: bill's billet bills @@ -116,4 +91,4 @@ co-op con coop */ -// +// From c37fe647fb6044023aa83a4bb0602e7f65e15c61 Mon Sep 17 00:00:00 2001 From: Dave Rayment Date: Fri, 5 Jul 2024 13:47:51 +0100 Subject: [PATCH 07/16] Create compareoptions_values.cpp New C++ example showing the effect of each of the CompareOptions values. --- .../CPP/compareoptions_values.cpp | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 snippets/cpp/VS_Snippets_CLR_System/system.Globalization.CompareOptions.Values/CPP/compareoptions_values.cpp diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Globalization.CompareOptions.Values/CPP/compareoptions_values.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Globalization.CompareOptions.Values/CPP/compareoptions_values.cpp new file mode 100644 index 00000000000..ef6239d58e9 --- /dev/null +++ b/snippets/cpp/VS_Snippets_CLR_System/system.Globalization.CompareOptions.Values/CPP/compareoptions_values.cpp @@ -0,0 +1,111 @@ +// +#include +#include + +using namespace System; +using namespace System::Globalization; + +public ref class CompareOptionsExample +{ +public: + static void Main() + { + // Uppercase and lowercase characters are equivalent (according to the culture rules) + // when IgnoreCase is used. + TestStringEquality("ONE two", "one TWO", "Case sensitivity", CompareOptions::IgnoreCase); + + // Punctuation is ignored with the IgnoreSymbols option. + TestStringEquality("hello world", "hello, world!", "Punctuation", CompareOptions::IgnoreSymbols); + + // Whitespace and mathematical symbols are also ignored with IgnoreSymbols. + TestStringEquality("3 + 5 = 8", "358", "Whitespace and mathematical symbols", CompareOptions::IgnoreSymbols); + + // Caution: currency symbols and thousands separators are ignored with IgnoreSymbols. + // Parse strings containing numbers/currency and compare them numerically instead. + TestStringEquality("Total $15,000", "Total: £150.00", "Currency symbols, decimals and thousands separators", CompareOptions::IgnoreSymbols); + + // Full width characters are common in East Asian languages. Use the IgnoreWidth + // option to treat full- and half-width characters as equal. + TestStringEquality("abc,-", "abc,-", "Half width and full width characters", CompareOptions::IgnoreWidth); + + // The same string in Hiragana and Katakana is equal when IgnoreKanaType is used. + TestStringEquality("ありがとう", "アリガトウ", "Hiragana and Katakana strings", CompareOptions::IgnoreKanaType); + + // When comparing with the IgnoreNonSpace option, characters like diacritical marks are ignored. + TestStringEquality("café", "cafe", "Diacritical marks", CompareOptions::IgnoreNonSpace); + + // Ligature characters and their non-ligature forms compare equal with the IgnoreNonSpace option. + // Note: prior to .NET 5, ligature characters were equal to their expanded forms by default. + TestStringEquality("straße œuvre cæsar", "strasse oeuvre caesar", "Ligature characters", CompareOptions::IgnoreNonSpace); + } + +private: + static void TestStringEquality(String^ str1, String^ str2, String^ description, CompareOptions options) + { + Console::WriteLine(Environment::NewLine + description + ":"); + // First test with the default CompareOptions then with the provided options + TestStringEquality(str1, str2, CompareOptions::None); + TestStringEquality(str1, str2, options); + } + + static void TestStringEquality(String^ str1, String^ str2, CompareOptions options) + { + Console::Write(" When using CompareOptions." + options + ", \"" + str1 + "\" and \"" + str2 + "\" are "); + if (String::Compare(str1, str2, CultureInfo::InvariantCulture, options) != 0) + { + Console::Write("not "); + } + Console::WriteLine("equal."); + } +}; + +int main(array ^args) +{ + CompareOptionsExample::Main(); + return 0; +} + +/* +In .NET 5 and later, the output will be the following: + +Case sensitivity: + When using CompareOptions.None, "ONE two" and "one TWO" are not equal. + When using CompareOptions.IgnoreCase, "ONE two" and "one TWO" are equal. + +Punctuation: + When using CompareOptions.None, "hello world" and "hello, world!" are not equal. + When using CompareOptions.IgnoreSymbols, "hello world" and "hello, world!" are equal. + +Whitespace and mathematical symbols: + When using CompareOptions.None, "3 + 5 = 8" and "358" are not equal. + When using CompareOptions.IgnoreSymbols, "3 + 5 = 8" and "358" are equal. + +Currency symbols, decimals and thousands separators: + When using CompareOptions.None, "Total $15,000" and "Total: £150.00" are not equal. + When using CompareOptions.IgnoreSymbols, "Total $15,000" and "Total: £150.00" are equal. + +Half width and full width characters: + When using CompareOptions.None, "abc,-" and "abc,-" are not equal. + When using CompareOptions.IgnoreWidth, "abc,-" and "abc,-" are equal. + +Hiragana and Katakana strings: + When using CompareOptions.None, "ありがとう" and "アリガトウ" are not equal. + When using CompareOptions.IgnoreKanaType, "ありがとう" and "アリガトウ" are equal. + +Diacritical marks: + When using CompareOptions.None, "café" and "cafe" are not equal. + When using CompareOptions.IgnoreNonSpace, "café" and "cafe" are equal. + +Ligature characters: + When using CompareOptions.None, "straße œuvre cæsar" and "strasse oeuvre caesar" are not equal. + When using CompareOptions.IgnoreNonSpace, "straße œuvre cæsar" and "strasse oeuvre caesar" are equal. + + +Note: when using .NET versions prior to .NET 5, ligature characters compare as equal to their +non-ligature counterparts by default, so the last test will output as follows: + +Ligature characters: + When using CompareOptions.None, "straße œuvre cæsar" and "strasse oeuvre caesar" are equal. + When using CompareOptions.IgnoreNonSpace, "straße œuvre cæsar" and "strasse oeuvre caesar" are equal. +*/ +// From a90e5600e9e2daaa8efd52d5d8d2ecb025cecb5a Mon Sep 17 00:00:00 2001 From: Dave Rayment Date: Fri, 5 Jul 2024 13:54:49 +0100 Subject: [PATCH 08/16] Create compareoptions_values.vb New VB example showing the effect of each of the CompareOptions values. --- .../VB/compareoptions_values.vb | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 snippets/visualbasic/system.Globalization.CompareOptions.Values/VB/compareoptions_values.vb diff --git a/snippets/visualbasic/system.Globalization.CompareOptions.Values/VB/compareoptions_values.vb b/snippets/visualbasic/system.Globalization.CompareOptions.Values/VB/compareoptions_values.vb new file mode 100644 index 00000000000..8c25841cfc6 --- /dev/null +++ b/snippets/visualbasic/system.Globalization.CompareOptions.Values/VB/compareoptions_values.vb @@ -0,0 +1,94 @@ +' +Imports System +Imports System.Globalization + +Module CompareOptionsExample + Sub Main() + ' Uppercase and lowercase characters are equivalent (according to the culture rules) + ' when IgnoreCase is used. + TestStringEquality("ONE two", "one TWO", "Case sensitivity", CompareOptions.IgnoreCase) + + ' Punctuation is ignored with the IgnoreSymbols option. + TestStringEquality("hello world", "hello, world!", "Punctuation", CompareOptions.IgnoreSymbols) + + ' Whitespace and mathematical symbols are also ignored with IgnoreSymbols. + TestStringEquality("3 + 5 = 8", "358", "Whitespace and mathematical symbols", CompareOptions.IgnoreSymbols) + + ' Caution: currency symbols and thousands separators are ignored with IgnoreSymbols. + ' Parse strings containing numbers/currency and compare them numerically instead. + TestStringEquality("Total $15,000", "Total: £150.00", "Currency symbols, decimals and thousands separators", CompareOptions.IgnoreSymbols) + + ' Full width characters are common in East Asian languages. Use the IgnoreWidth + ' option to treat full- and half-width characters as equal. + TestStringEquality("abc,-", "abc,-", "Half width and full width characters", CompareOptions.IgnoreWidth) + + ' The same string in Hiragana and Katakana is equal when IgnoreKanaType is used. + TestStringEquality("ありがとう", "アリガトウ", "Hiragana and Katakana strings", CompareOptions.IgnoreKanaType) + + ' When comparing with the IgnoreNonSpace option, characters like diacritical marks are ignored. + TestStringEquality("café", "cafe", "Diacritical marks", CompareOptions.IgnoreNonSpace) + + ' Ligature characters and their non-ligature forms compare equal with the IgnoreNonSpace option. + ' Note: prior to .NET 5, ligature characters were equal to their expanded forms by default. + TestStringEquality("straße œuvre cæsar", "strasse oeuvre caesar", "Ligature characters", CompareOptions.IgnoreNonSpace) + End Sub + + Private Sub TestStringEquality(str1 As String, str2 As String, description As String, options As CompareOptions) + Console.WriteLine(Environment.NewLine & description & ":") + ' First test with the default CompareOptions then with the provided options + TestStringEqualityWithOptions(str1, str2, CompareOptions.None) + TestStringEqualityWithOptions(str1, str2, options) + End Sub + + Private Sub TestStringEqualityWithOptions(str1 As String, str2 As String, options As CompareOptions) + Console.Write($" When using CompareOptions.{options}, ""{str1}"" and ""{str2}"" are ") + If String.Compare(str1, str2, CultureInfo.InvariantCulture, options) <> 0 Then + Console.Write("not ") + End If + Console.WriteLine("equal.") + End Sub +End Module + +' In .NET 5 and later, the output will be the following: +' +'Case sensitivity : +' When using CompareOptions.None, "ONE two" and "one TWO" are not equal. +' When using CompareOptions.IgnoreCase, "ONE two" and "one TWO" are equal. +' +'Punctuation: +' When using CompareOptions.None, "hello world" and "hello, world!" are not equal. +' When using CompareOptions.IgnoreSymbols, "hello world" and "hello, world!" are equal. +' +'Whitespace And mathematical symbols: +' When using CompareOptions.None, "3 + 5 = 8" and "358" are not equal. +' When using CompareOptions.IgnoreSymbols, "3 + 5 = 8" and "358" are equal. +' +'Currency symbols, decimals And thousands separators: +' When using CompareOptions.None, "Total $15,000" and "Total: £150.00" are not equal. +' When using CompareOptions.IgnoreSymbols, "Total $15,000" and "Total: £150.00" are equal. +' +'Half width And full width characters: +' When using CompareOptions.None, "abc,-" and "abc,-" are not equal. +' When using CompareOptions.IgnoreWidth, "abc,-" and "abc,-" are equal. +' +'Hiragana And Katakana strings: +' When using CompareOptions.None, "ありがとう" and "アリガトウ" are not equal. +' When using CompareOptions.IgnoreKanaType, "ありがとう" and "アリガトウ" are equal. +' +'Diacritical marks : +' When using CompareOptions.None, "café" and "cafe" are not equal. +' When using CompareOptions.IgnoreNonSpace, "café" and "cafe" are equal. +' +'Ligature characters : +' When using CompareOptions.None, "straße œuvre cæsar" and "strasse oeuvre caesar" are not equal. +' When using CompareOptions.IgnoreNonSpace, "straße œuvre cæsar" and "strasse oeuvre caesar" are equal. +' +' +' Note: when using .NET versions prior to .NET 5, ligature characters compare as equal to their +' non-ligature counterparts by default, so the last test will output as follows: +' +'Ligature characters : +' When using CompareOptions.None, "straße œuvre cæsar" and "strasse oeuvre caesar" are equal. +' When using CompareOptions.IgnoreNonSpace, "straße œuvre cæsar" and "strasse oeuvre caesar" are equal. + +' From 1ad3624215278ae6a3e4dc0f5e210e45ba0ac37e Mon Sep 17 00:00:00 2001 From: Dave Rayment Date: Fri, 5 Jul 2024 14:19:08 +0100 Subject: [PATCH 09/16] Delete snippets/visualbasic/system.Globalization.CompareOptions.Values/VB/compareoptions_values.vb Remove misplaced file. --- .../VB/compareoptions_values.vb | 94 ------------------- 1 file changed, 94 deletions(-) delete mode 100644 snippets/visualbasic/system.Globalization.CompareOptions.Values/VB/compareoptions_values.vb diff --git a/snippets/visualbasic/system.Globalization.CompareOptions.Values/VB/compareoptions_values.vb b/snippets/visualbasic/system.Globalization.CompareOptions.Values/VB/compareoptions_values.vb deleted file mode 100644 index 8c25841cfc6..00000000000 --- a/snippets/visualbasic/system.Globalization.CompareOptions.Values/VB/compareoptions_values.vb +++ /dev/null @@ -1,94 +0,0 @@ -' -Imports System -Imports System.Globalization - -Module CompareOptionsExample - Sub Main() - ' Uppercase and lowercase characters are equivalent (according to the culture rules) - ' when IgnoreCase is used. - TestStringEquality("ONE two", "one TWO", "Case sensitivity", CompareOptions.IgnoreCase) - - ' Punctuation is ignored with the IgnoreSymbols option. - TestStringEquality("hello world", "hello, world!", "Punctuation", CompareOptions.IgnoreSymbols) - - ' Whitespace and mathematical symbols are also ignored with IgnoreSymbols. - TestStringEquality("3 + 5 = 8", "358", "Whitespace and mathematical symbols", CompareOptions.IgnoreSymbols) - - ' Caution: currency symbols and thousands separators are ignored with IgnoreSymbols. - ' Parse strings containing numbers/currency and compare them numerically instead. - TestStringEquality("Total $15,000", "Total: £150.00", "Currency symbols, decimals and thousands separators", CompareOptions.IgnoreSymbols) - - ' Full width characters are common in East Asian languages. Use the IgnoreWidth - ' option to treat full- and half-width characters as equal. - TestStringEquality("abc,-", "abc,-", "Half width and full width characters", CompareOptions.IgnoreWidth) - - ' The same string in Hiragana and Katakana is equal when IgnoreKanaType is used. - TestStringEquality("ありがとう", "アリガトウ", "Hiragana and Katakana strings", CompareOptions.IgnoreKanaType) - - ' When comparing with the IgnoreNonSpace option, characters like diacritical marks are ignored. - TestStringEquality("café", "cafe", "Diacritical marks", CompareOptions.IgnoreNonSpace) - - ' Ligature characters and their non-ligature forms compare equal with the IgnoreNonSpace option. - ' Note: prior to .NET 5, ligature characters were equal to their expanded forms by default. - TestStringEquality("straße œuvre cæsar", "strasse oeuvre caesar", "Ligature characters", CompareOptions.IgnoreNonSpace) - End Sub - - Private Sub TestStringEquality(str1 As String, str2 As String, description As String, options As CompareOptions) - Console.WriteLine(Environment.NewLine & description & ":") - ' First test with the default CompareOptions then with the provided options - TestStringEqualityWithOptions(str1, str2, CompareOptions.None) - TestStringEqualityWithOptions(str1, str2, options) - End Sub - - Private Sub TestStringEqualityWithOptions(str1 As String, str2 As String, options As CompareOptions) - Console.Write($" When using CompareOptions.{options}, ""{str1}"" and ""{str2}"" are ") - If String.Compare(str1, str2, CultureInfo.InvariantCulture, options) <> 0 Then - Console.Write("not ") - End If - Console.WriteLine("equal.") - End Sub -End Module - -' In .NET 5 and later, the output will be the following: -' -'Case sensitivity : -' When using CompareOptions.None, "ONE two" and "one TWO" are not equal. -' When using CompareOptions.IgnoreCase, "ONE two" and "one TWO" are equal. -' -'Punctuation: -' When using CompareOptions.None, "hello world" and "hello, world!" are not equal. -' When using CompareOptions.IgnoreSymbols, "hello world" and "hello, world!" are equal. -' -'Whitespace And mathematical symbols: -' When using CompareOptions.None, "3 + 5 = 8" and "358" are not equal. -' When using CompareOptions.IgnoreSymbols, "3 + 5 = 8" and "358" are equal. -' -'Currency symbols, decimals And thousands separators: -' When using CompareOptions.None, "Total $15,000" and "Total: £150.00" are not equal. -' When using CompareOptions.IgnoreSymbols, "Total $15,000" and "Total: £150.00" are equal. -' -'Half width And full width characters: -' When using CompareOptions.None, "abc,-" and "abc,-" are not equal. -' When using CompareOptions.IgnoreWidth, "abc,-" and "abc,-" are equal. -' -'Hiragana And Katakana strings: -' When using CompareOptions.None, "ありがとう" and "アリガトウ" are not equal. -' When using CompareOptions.IgnoreKanaType, "ありがとう" and "アリガトウ" are equal. -' -'Diacritical marks : -' When using CompareOptions.None, "café" and "cafe" are not equal. -' When using CompareOptions.IgnoreNonSpace, "café" and "cafe" are equal. -' -'Ligature characters : -' When using CompareOptions.None, "straße œuvre cæsar" and "strasse oeuvre caesar" are not equal. -' When using CompareOptions.IgnoreNonSpace, "straße œuvre cæsar" and "strasse oeuvre caesar" are equal. -' -' -' Note: when using .NET versions prior to .NET 5, ligature characters compare as equal to their -' non-ligature counterparts by default, so the last test will output as follows: -' -'Ligature characters : -' When using CompareOptions.None, "straße œuvre cæsar" and "strasse oeuvre caesar" are equal. -' When using CompareOptions.IgnoreNonSpace, "straße œuvre cæsar" and "strasse oeuvre caesar" are equal. - -' From ac97b739461331ee448b182092bf2eaba00ecb2d Mon Sep 17 00:00:00 2001 From: Dave Rayment Date: Fri, 5 Jul 2024 14:21:09 +0100 Subject: [PATCH 10/16] Create compareoptions_values.vb New VB example showing the effect of each of the CompareOptions values. --- .../VB/compareoptions_values.vb | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 snippets/visualbasic/VS_Snippets_CLR_System/system.Globalization.CompareOptions.Values/VB/compareoptions_values.vb diff --git a/snippets/visualbasic/VS_Snippets_CLR_System/system.Globalization.CompareOptions.Values/VB/compareoptions_values.vb b/snippets/visualbasic/VS_Snippets_CLR_System/system.Globalization.CompareOptions.Values/VB/compareoptions_values.vb new file mode 100644 index 00000000000..8c25841cfc6 --- /dev/null +++ b/snippets/visualbasic/VS_Snippets_CLR_System/system.Globalization.CompareOptions.Values/VB/compareoptions_values.vb @@ -0,0 +1,94 @@ +' +Imports System +Imports System.Globalization + +Module CompareOptionsExample + Sub Main() + ' Uppercase and lowercase characters are equivalent (according to the culture rules) + ' when IgnoreCase is used. + TestStringEquality("ONE two", "one TWO", "Case sensitivity", CompareOptions.IgnoreCase) + + ' Punctuation is ignored with the IgnoreSymbols option. + TestStringEquality("hello world", "hello, world!", "Punctuation", CompareOptions.IgnoreSymbols) + + ' Whitespace and mathematical symbols are also ignored with IgnoreSymbols. + TestStringEquality("3 + 5 = 8", "358", "Whitespace and mathematical symbols", CompareOptions.IgnoreSymbols) + + ' Caution: currency symbols and thousands separators are ignored with IgnoreSymbols. + ' Parse strings containing numbers/currency and compare them numerically instead. + TestStringEquality("Total $15,000", "Total: £150.00", "Currency symbols, decimals and thousands separators", CompareOptions.IgnoreSymbols) + + ' Full width characters are common in East Asian languages. Use the IgnoreWidth + ' option to treat full- and half-width characters as equal. + TestStringEquality("abc,-", "abc,-", "Half width and full width characters", CompareOptions.IgnoreWidth) + + ' The same string in Hiragana and Katakana is equal when IgnoreKanaType is used. + TestStringEquality("ありがとう", "アリガトウ", "Hiragana and Katakana strings", CompareOptions.IgnoreKanaType) + + ' When comparing with the IgnoreNonSpace option, characters like diacritical marks are ignored. + TestStringEquality("café", "cafe", "Diacritical marks", CompareOptions.IgnoreNonSpace) + + ' Ligature characters and their non-ligature forms compare equal with the IgnoreNonSpace option. + ' Note: prior to .NET 5, ligature characters were equal to their expanded forms by default. + TestStringEquality("straße œuvre cæsar", "strasse oeuvre caesar", "Ligature characters", CompareOptions.IgnoreNonSpace) + End Sub + + Private Sub TestStringEquality(str1 As String, str2 As String, description As String, options As CompareOptions) + Console.WriteLine(Environment.NewLine & description & ":") + ' First test with the default CompareOptions then with the provided options + TestStringEqualityWithOptions(str1, str2, CompareOptions.None) + TestStringEqualityWithOptions(str1, str2, options) + End Sub + + Private Sub TestStringEqualityWithOptions(str1 As String, str2 As String, options As CompareOptions) + Console.Write($" When using CompareOptions.{options}, ""{str1}"" and ""{str2}"" are ") + If String.Compare(str1, str2, CultureInfo.InvariantCulture, options) <> 0 Then + Console.Write("not ") + End If + Console.WriteLine("equal.") + End Sub +End Module + +' In .NET 5 and later, the output will be the following: +' +'Case sensitivity : +' When using CompareOptions.None, "ONE two" and "one TWO" are not equal. +' When using CompareOptions.IgnoreCase, "ONE two" and "one TWO" are equal. +' +'Punctuation: +' When using CompareOptions.None, "hello world" and "hello, world!" are not equal. +' When using CompareOptions.IgnoreSymbols, "hello world" and "hello, world!" are equal. +' +'Whitespace And mathematical symbols: +' When using CompareOptions.None, "3 + 5 = 8" and "358" are not equal. +' When using CompareOptions.IgnoreSymbols, "3 + 5 = 8" and "358" are equal. +' +'Currency symbols, decimals And thousands separators: +' When using CompareOptions.None, "Total $15,000" and "Total: £150.00" are not equal. +' When using CompareOptions.IgnoreSymbols, "Total $15,000" and "Total: £150.00" are equal. +' +'Half width And full width characters: +' When using CompareOptions.None, "abc,-" and "abc,-" are not equal. +' When using CompareOptions.IgnoreWidth, "abc,-" and "abc,-" are equal. +' +'Hiragana And Katakana strings: +' When using CompareOptions.None, "ありがとう" and "アリガトウ" are not equal. +' When using CompareOptions.IgnoreKanaType, "ありがとう" and "アリガトウ" are equal. +' +'Diacritical marks : +' When using CompareOptions.None, "café" and "cafe" are not equal. +' When using CompareOptions.IgnoreNonSpace, "café" and "cafe" are equal. +' +'Ligature characters : +' When using CompareOptions.None, "straße œuvre cæsar" and "strasse oeuvre caesar" are not equal. +' When using CompareOptions.IgnoreNonSpace, "straße œuvre cæsar" and "strasse oeuvre caesar" are equal. +' +' +' Note: when using .NET versions prior to .NET 5, ligature characters compare as equal to their +' non-ligature counterparts by default, so the last test will output as follows: +' +'Ligature characters : +' When using CompareOptions.None, "straße œuvre cæsar" and "strasse oeuvre caesar" are equal. +' When using CompareOptions.IgnoreNonSpace, "straße œuvre cæsar" and "strasse oeuvre caesar" are equal. + +' From a5e9fb8cfe1dd10bd61e666a2f59888811919c1e Mon Sep 17 00:00:00 2001 From: Dave Rayment Date: Fri, 5 Jul 2024 14:40:12 +0100 Subject: [PATCH 11/16] Update CompareOptions.xml Updated descriptions for each of the options. New introduction, including notes about the StringSort and ligature character changes in .NET 5. Links added to updated and new example code for all supported languages. --- xml/System.Globalization/CompareOptions.xml | 59 +++++++++++++++------ 1 file changed, 44 insertions(+), 15 deletions(-) diff --git a/xml/System.Globalization/CompareOptions.xml b/xml/System.Globalization/CompareOptions.xml index 5bd6fa0ea24..af4b060ebfb 100644 --- a/xml/System.Globalization/CompareOptions.xml +++ b/xml/System.Globalization/CompareOptions.xml @@ -68,15 +68,44 @@ - Defines the string comparison options to use with . - For more information about this API, see Supplemental API remarks for CompareOptions. + + Defines the string comparison options to use with . + + + + + + + The following code example shows how each of the CompareOptions values affect string comparisons. + + + + The following code example shows how sorting with StringSort differs from sorting without StringSort. - + + + + Basic String Operations in .NET @@ -121,7 +150,7 @@ 1 - Indicates that the string comparison must ignore case. + Indicates that the string comparison ignores case differences. @@ -165,7 +194,7 @@ 8 - Indicates that the string comparison must ignore the Kana type. Kana type refers to Japanese hiragana and katakana characters, which represent phonetic sounds in the Japanese language. Hiragana is used for native Japanese expressions and words, while katakana is used for words borrowed from other languages, such as "computer" or "Internet". A phonetic sound can be expressed in both hiragana and katakana. If this value is selected, the hiragana character for one sound is considered equal to the katakana character for the same sound. + Indicates that the string comparison ignores the Kana type. Kana type refers to Japanese Hiragana and Katakana characters, which represent phonetic sounds. Hiragana is used for native Japanese words, while Katakana is used for loanwords and foreign names. With this option, Hiragana and Katakana characters representing the same sound are considered equal. @@ -209,7 +238,7 @@ 2 - Indicates that the string comparison must ignore nonspacing combining characters, such as diacritics. The Unicode Standard defines combining characters as characters that are combined with base characters to produce a new character. Nonspacing combining characters do not occupy a spacing position by themselves when rendered. + Indicates that the string comparison ignores non-spacing combining characters, such as diacritics. Non-spacing characters modify base characters without occupying their own space. The Unicode Standard defines these characters. @@ -253,7 +282,7 @@ 4 - Indicates that the string comparison must ignore symbols, such as white-space characters, punctuation, currency symbols, the percent sign, mathematical symbols, the ampersand, and so on. + Indicates that the string comparison ignores symbols, including whitespace, punctuation, currency symbols, the percent sign, mathematical symbols, the ampersand, and similar characters. @@ -297,7 +326,7 @@ 16 - Indicates that the string comparison must ignore the character width. For example, Japanese katakana characters can be written as full-width or half-width. If this value is selected, the katakana characters written as full-width are considered equal to the same characters written as half-width. + Indicates that the string comparison ignores character width. For example, full-width and half-width forms of Japanese Katakana characters are considered equal with this option. @@ -385,7 +414,7 @@ 1073741824 - Indicates that the string comparison must use successive Unicode UTF-16 encoded values of the string (code unit by code unit comparison), leading to a fast comparison but one that is culture-insensitive. A string starting with a code unit XXXX16 comes before a string starting with YYYY16, if XXXX16 is less than YYYY16. This value cannot be combined with other values and must be used alone. + Indicates that the string comparison uses the Unicode UTF-16 encoded values of the strings, comparing them code unit by code unit. This results in a fast, culture-insensitive comparison where strings are ordered based only on their binary values. This option cannot be combined with other values and must be used alone. @@ -428,7 +457,7 @@ 268435456 - String comparison must ignore case, then perform an ordinal comparison. This technique is equivalent to converting the string to uppercase using the invariant culture and then performing an ordinal comparison on the result. + Indicates that the string comparison ignores case and then performs an ordinal comparison. This is equivalent to converting both strings to uppercase using the invariant culture before performing the comparison. @@ -472,7 +501,7 @@ 536870912 - Indicates that the string comparison must use the string sort algorithm. In a string sort, the hyphen and the apostrophe, as well as other nonalphanumeric symbols, come before alphanumeric characters. + Indicates that the string comparison uses the string sort algorithm, where non-alphanumeric symbols (such as hyphens and apostrophes) are sorted before alphanumeric characters. From 7ff5368cdcf027de53e3601dc413c3db533991b0 Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Wed, 2 Apr 2025 18:37:54 -0700 Subject: [PATCH 12/16] fix errors/warnings --- .../CompareOptions/Overview/Program.cs | 2 ++ .../CompareOptions/Overview/Project.csproj | 4 +-- .../Overview/compareoptions_stringsort.cs | 10 +++--- .../Overview/compareoptions_values.cs | 11 +++---- .../System.Globalization/Project.fsproj | 13 ++++++++ .../compareoptions_stringsort.fs | 10 +++--- .../compareoptions_values.fs | 10 +++--- .../VB/Project.vbproj | 8 +++++ .../VB/compareoptions_stringsort.vb | 5 +-- .../VB/Project.vbproj | 8 +++++ .../VB/compareoptions_values.vb | 14 +++----- xml/System.Globalization/CompareOptions.xml | 32 +++++++++---------- 12 files changed, 70 insertions(+), 57 deletions(-) create mode 100644 snippets/csharp/System.Globalization/CompareOptions/Overview/Program.cs create mode 100644 snippets/fsharp/System.Globalization/Project.fsproj create mode 100644 snippets/visualbasic/VS_Snippets_CLR_System/system.Globalization.CompareOptions.StringSort/VB/Project.vbproj create mode 100644 snippets/visualbasic/VS_Snippets_CLR_System/system.Globalization.CompareOptions.Values/VB/Project.vbproj diff --git a/snippets/csharp/System.Globalization/CompareOptions/Overview/Program.cs b/snippets/csharp/System.Globalization/CompareOptions/Overview/Program.cs new file mode 100644 index 00000000000..120ab0719ff --- /dev/null +++ b/snippets/csharp/System.Globalization/CompareOptions/Overview/Program.cs @@ -0,0 +1,2 @@ +CompareOptionsExample.Run(); +StringSort.Run(); diff --git a/snippets/csharp/System.Globalization/CompareOptions/Overview/Project.csproj b/snippets/csharp/System.Globalization/CompareOptions/Overview/Project.csproj index c02dc5044e7..325ccd545c2 100644 --- a/snippets/csharp/System.Globalization/CompareOptions/Overview/Project.csproj +++ b/snippets/csharp/System.Globalization/CompareOptions/Overview/Project.csproj @@ -1,8 +1,8 @@ - Library - net6.0 + Exe + net9.0 \ No newline at end of file diff --git a/snippets/csharp/System.Globalization/CompareOptions/Overview/compareoptions_stringsort.cs b/snippets/csharp/System.Globalization/CompareOptions/Overview/compareoptions_stringsort.cs index 65efc20e8ce..849675dcef8 100644 --- a/snippets/csharp/System.Globalization/CompareOptions/Overview/compareoptions_stringsort.cs +++ b/snippets/csharp/System.Globalization/CompareOptions/Overview/compareoptions_stringsort.cs @@ -1,11 +1,10 @@ -// -using System; +using System; using System.Collections.Generic; using System.Globalization; public class StringSort { - public static void Main() + public static void Run() { var wordList = new List { @@ -31,7 +30,7 @@ private static void SortAndDisplay(List unsorted, CompareOptions options // Create a copy of the original list to sort. var words = new List(unsorted); // Define the CompareInfo to use to compare strings. - var comparer = CultureInfo.InvariantCulture.CompareInfo; + CompareInfo comparer = CultureInfo.InvariantCulture.CompareInfo; // Sort the copy with the supplied CompareOptions then display. words.Sort((str1, str2) => comparer.Compare(str1, str2, options)); @@ -44,7 +43,7 @@ private static void SortAndDisplay(List unsorted, CompareOptions options /* CompareOptions.None and CompareOptions.StringSort provide identical ordering by default -in .NET 5 and later, but in prior versions, the output will be the following: +in .NET 5 and later. But in prior versions, the output is the following: Before sorting: cant @@ -79,4 +78,3 @@ private static void SortAndDisplay(List unsorted, CompareOptions options con coop */ -// diff --git a/snippets/csharp/System.Globalization/CompareOptions/Overview/compareoptions_values.cs b/snippets/csharp/System.Globalization/CompareOptions/Overview/compareoptions_values.cs index 99927dd7f5f..05e9124a430 100644 --- a/snippets/csharp/System.Globalization/CompareOptions/Overview/compareoptions_values.cs +++ b/snippets/csharp/System.Globalization/CompareOptions/Overview/compareoptions_values.cs @@ -1,10 +1,9 @@ -// -using System; +using System; using System.Globalization; public class CompareOptionsExample { - public static void Main() + public static void Run() { // Uppercase and lowercase characters are equivalent (according to the culture rules) // when IgnoreCase is used. @@ -55,7 +54,7 @@ private static void TestStringEquality(string str1, string str2, CompareOptions } /* -In .NET 5 and later, the output will be the following: +In .NET 5 and later, the output is the following: Case sensitivity: When using CompareOptions.None, "ONE two" and "one TWO" are not equal. @@ -89,12 +88,10 @@ private static void TestStringEquality(string str1, string str2, CompareOptions When using CompareOptions.None, "straße œuvre cæsar" and "strasse oeuvre caesar" are not equal. When using CompareOptions.IgnoreNonSpace, "straße œuvre cæsar" and "strasse oeuvre caesar" are equal. - -Note: when using .NET versions prior to .NET 5, ligature characters compare as equal to their +Note: When using .NET versions prior to .NET 5, ligature characters compare as equal to their non-ligature counterparts by default, so the last test will output as follows: Ligature characters: When using CompareOptions.None, "straße œuvre cæsar" and "strasse oeuvre caesar" are equal. When using CompareOptions.IgnoreNonSpace, "straße œuvre cæsar" and "strasse oeuvre caesar" are equal. */ -// \ No newline at end of file diff --git a/snippets/fsharp/System.Globalization/Project.fsproj b/snippets/fsharp/System.Globalization/Project.fsproj new file mode 100644 index 00000000000..145f21d0946 --- /dev/null +++ b/snippets/fsharp/System.Globalization/Project.fsproj @@ -0,0 +1,13 @@ + + + + Library + net9.0 + + + + + + + + diff --git a/snippets/fsharp/System.Globalization/compareoptions_stringsort.fs b/snippets/fsharp/System.Globalization/compareoptions_stringsort.fs index b47864e0755..6b537c1bc1e 100644 --- a/snippets/fsharp/System.Globalization/compareoptions_stringsort.fs +++ b/snippets/fsharp/System.Globalization/compareoptions_stringsort.fs @@ -1,4 +1,3 @@ -// open System open System.Collections.Generic open System.Globalization @@ -14,17 +13,17 @@ let sortAndDisplay (unsorted: List) (options: CompareOptions) = let main argv = let wordList = new List( ["cant"; "bill's"; "coop"; "cannot"; "billet"; "can't"; "con"; "bills"; "co-op"]) - + printfn "Before sorting:" for word in wordList do printfn "%s" word - + printfn "\nAfter sorting with CompareOptions.None:" sortAndDisplay wordList CompareOptions.None - + printfn "\nAfter sorting with CompareOptions.StringSort:" sortAndDisplay wordList CompareOptions.StringSort - + 0 // return an integer exit code (* @@ -64,4 +63,3 @@ co-op con coop *) -// diff --git a/snippets/fsharp/System.Globalization/compareoptions_values.fs b/snippets/fsharp/System.Globalization/compareoptions_values.fs index d80b46ca732..d6dc803a586 100644 --- a/snippets/fsharp/System.Globalization/compareoptions_values.fs +++ b/snippets/fsharp/System.Globalization/compareoptions_values.fs @@ -1,10 +1,9 @@ -// -open System +open System open System.Globalization let testStringEquality (str1: string) (str2: string) (description: string) (options: CompareOptions) = printfn "\n%s:" description - + let compareAndPrint opts = let result = String.Compare(str1, str2, CultureInfo.InvariantCulture, opts) let equalityStatus = if result = 0 then "equal" else "not equal" @@ -41,12 +40,12 @@ let main argv = // Ligature characters and their non-ligature forms compare equal with the IgnoreNonSpace option. // Note: prior to .NET 5, ligature characters were equal to their expanded forms by default. testStringEquality "straße œuvre cæsar" "strasse oeuvre caesar" "Ligature characters" CompareOptions.IgnoreNonSpace - + 0 // return an integer exit code (* In .NET 5 and later, the output will be the following: - + Case sensitivity: When using CompareOptions.None, "ONE two" and "one TWO" are not equal. When using CompareOptions.IgnoreCase, "ONE two" and "one TWO" are equal. @@ -87,4 +86,3 @@ Ligature characters: When using CompareOptions.None, "straße œuvre cæsar" and "strasse oeuvre caesar" are equal. When using CompareOptions.IgnoreNonSpace, "straße œuvre cæsar" and "strasse oeuvre caesar" are equal. *) -// \ No newline at end of file diff --git a/snippets/visualbasic/VS_Snippets_CLR_System/system.Globalization.CompareOptions.StringSort/VB/Project.vbproj b/snippets/visualbasic/VS_Snippets_CLR_System/system.Globalization.CompareOptions.StringSort/VB/Project.vbproj new file mode 100644 index 00000000000..92e46ddaccf --- /dev/null +++ b/snippets/visualbasic/VS_Snippets_CLR_System/system.Globalization.CompareOptions.StringSort/VB/Project.vbproj @@ -0,0 +1,8 @@ + + + + Exe + net9.0 + + + diff --git a/snippets/visualbasic/VS_Snippets_CLR_System/system.Globalization.CompareOptions.StringSort/VB/compareoptions_stringsort.vb b/snippets/visualbasic/VS_Snippets_CLR_System/system.Globalization.CompareOptions.StringSort/VB/compareoptions_stringsort.vb index 5e8e0feed0a..164042db7b6 100644 --- a/snippets/visualbasic/VS_Snippets_CLR_System/system.Globalization.CompareOptions.StringSort/VB/compareoptions_stringsort.vb +++ b/snippets/visualbasic/VS_Snippets_CLR_System/system.Globalization.CompareOptions.StringSort/VB/compareoptions_stringsort.vb @@ -1,4 +1,3 @@ -'// Imports System Imports System.Collections.Generic Imports System.Globalization @@ -39,7 +38,7 @@ Public Class StringSort End Class ' CompareOptions.None and CompareOptions.StringSort provide identical ordering by default -' in .NET 5 And later, but in prior versions, the output will be the following: +' in .NET 5 And later, but in prior versions, the output is the following: ' 'Before sorting 'cant @@ -73,5 +72,3 @@ End Class 'co-op 'con 'coop - -'// diff --git a/snippets/visualbasic/VS_Snippets_CLR_System/system.Globalization.CompareOptions.Values/VB/Project.vbproj b/snippets/visualbasic/VS_Snippets_CLR_System/system.Globalization.CompareOptions.Values/VB/Project.vbproj new file mode 100644 index 00000000000..92e46ddaccf --- /dev/null +++ b/snippets/visualbasic/VS_Snippets_CLR_System/system.Globalization.CompareOptions.Values/VB/Project.vbproj @@ -0,0 +1,8 @@ + + + + Exe + net9.0 + + + diff --git a/snippets/visualbasic/VS_Snippets_CLR_System/system.Globalization.CompareOptions.Values/VB/compareoptions_values.vb b/snippets/visualbasic/VS_Snippets_CLR_System/system.Globalization.CompareOptions.Values/VB/compareoptions_values.vb index 8c25841cfc6..885a8c140fe 100644 --- a/snippets/visualbasic/VS_Snippets_CLR_System/system.Globalization.CompareOptions.Values/VB/compareoptions_values.vb +++ b/snippets/visualbasic/VS_Snippets_CLR_System/system.Globalization.CompareOptions.Values/VB/compareoptions_values.vb @@ -1,4 +1,3 @@ -' Imports System Imports System.Globalization @@ -49,9 +48,9 @@ Module CompareOptionsExample End Sub End Module -' In .NET 5 and later, the output will be the following: +' In .NET 5 and later, the output is the following: ' -'Case sensitivity : +'Case sensitivity : ' When using CompareOptions.None, "ONE two" and "one TWO" are not equal. ' When using CompareOptions.IgnoreCase, "ONE two" and "one TWO" are equal. ' @@ -75,20 +74,17 @@ End Module ' When using CompareOptions.None, "ありがとう" and "アリガトウ" are not equal. ' When using CompareOptions.IgnoreKanaType, "ありがとう" and "アリガトウ" are equal. ' -'Diacritical marks : +'Diacritical marks : ' When using CompareOptions.None, "café" and "cafe" are not equal. ' When using CompareOptions.IgnoreNonSpace, "café" and "cafe" are equal. ' -'Ligature characters : +'Ligature characters : ' When using CompareOptions.None, "straße œuvre cæsar" and "strasse oeuvre caesar" are not equal. ' When using CompareOptions.IgnoreNonSpace, "straße œuvre cæsar" and "strasse oeuvre caesar" are equal. ' -' ' Note: when using .NET versions prior to .NET 5, ligature characters compare as equal to their ' non-ligature counterparts by default, so the last test will output as follows: ' -'Ligature characters : +'Ligature characters : ' When using CompareOptions.None, "straße œuvre cæsar" and "strasse oeuvre caesar" are equal. ' When using CompareOptions.IgnoreNonSpace, "straße œuvre cæsar" and "strasse oeuvre caesar" are equal. - -' diff --git a/xml/System.Globalization/CompareOptions.xml b/xml/System.Globalization/CompareOptions.xml index af4b060ebfb..419e8d43e63 100644 --- a/xml/System.Globalization/CompareOptions.xml +++ b/xml/System.Globalization/CompareOptions.xml @@ -74,12 +74,12 @@ @@ -88,9 +88,8 @@ The following code example shows how each of the CompareOptions values affect string comparisons. @@ -99,9 +98,8 @@ The following code example shows how sorting with StringSort differs from sorting without StringSort. @@ -194,7 +192,7 @@ 8 - Indicates that the string comparison ignores the Kana type. Kana type refers to Japanese Hiragana and Katakana characters, which represent phonetic sounds. Hiragana is used for native Japanese words, while Katakana is used for loanwords and foreign names. With this option, Hiragana and Katakana characters representing the same sound are considered equal. + Indicates that the string comparison ignores the kana type. Kana type refers to Japanese hiragana and katakana characters, which represent phonetic sounds. Hiragana is used for native Japanese words, while katakana is used for words borrowed from other languages. With this option, hiragana and katakana characters that represent the same sound are considered equal. @@ -238,7 +236,7 @@ 2 - Indicates that the string comparison ignores non-spacing combining characters, such as diacritics. Non-spacing characters modify base characters without occupying their own space. The Unicode Standard defines these characters. + Indicates that the string comparison ignores nonspacing combining characters, such as diacritics. Nonspacing characters modify base characters without occupying their own space. The Unicode Standard defines combining characters as characters that are combined with base characters to produce a new character. @@ -326,7 +324,7 @@ 16 - Indicates that the string comparison ignores character width. For example, full-width and half-width forms of Japanese Katakana characters are considered equal with this option. + Indicates that the string comparison ignores character width. For example, full-width and half-width forms of Japanese katakana characters are considered equal with this option. @@ -414,7 +412,7 @@ 1073741824 - Indicates that the string comparison uses the Unicode UTF-16 encoded values of the strings, comparing them code unit by code unit. This results in a fast, culture-insensitive comparison where strings are ordered based only on their binary values. This option cannot be combined with other values and must be used alone. + Indicates that the string comparison uses the Unicode UTF-16 encoded values of the strings, comparing them code unit by code unit. This results in a fast, culture-insensitive comparison where strings are ordered based only on their binary values. This option can't be combined with other values and must be used alone. @@ -457,7 +455,7 @@ 268435456 - Indicates that the string comparison ignores case and then performs an ordinal comparison. This is equivalent to converting both strings to uppercase using the invariant culture before performing the comparison. + Indicates that the string comparison ignores case and then performs an ordinal comparison. This is equivalent to converting both strings to uppercase using the invariant culture and then performing the comparison. @@ -501,7 +499,7 @@ 536870912 - Indicates that the string comparison uses the string sort algorithm, where non-alphanumeric symbols (such as hyphens and apostrophes) are sorted before alphanumeric characters. + Indicates that the string comparison uses the string sort algorithm, where nonalphanumeric symbols (such as hyphens and apostrophes) are sorted before alphanumeric characters. From 853b27b34c454801e29bac753a7aa91fc48a9d99 Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Wed, 2 Apr 2025 18:39:29 -0700 Subject: [PATCH 13/16] delete c++ snippets --- .../CPP/compareoptions_stringsort.cpp | 94 ------------------- .../VB/compareoptions_values.vb | 90 ------------------ 2 files changed, 184 deletions(-) delete mode 100644 snippets/cpp/VS_Snippets_CLR_System/system.Globalization.CompareOptions.StringSort/CPP/compareoptions_stringsort.cpp delete mode 100644 snippets/visualbasic/VS_Snippets_CLR_System/system.Globalization.CompareOptions.Values/VB/compareoptions_values.vb diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Globalization.CompareOptions.StringSort/CPP/compareoptions_stringsort.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Globalization.CompareOptions.StringSort/CPP/compareoptions_stringsort.cpp deleted file mode 100644 index 02d0766c4fe..00000000000 --- a/snippets/cpp/VS_Snippets_CLR_System/system.Globalization.CompareOptions.StringSort/CPP/compareoptions_stringsort.cpp +++ /dev/null @@ -1,94 +0,0 @@ -// -#include -#using - -using namespace System; -using namespace System::Collections::Generic; -using namespace System::Globalization; - -ref class StringSort -{ -public: - static void Main() - { - auto wordList = gcnew List { - "cant", "bill's", "coop", "cannot", "billet", "can't", "con", "bills", "co-op" - }; - - Console::WriteLine("Before sorting:"); - for each (String^ word in wordList) - { - Console::WriteLine(word); - } - - Console::WriteLine(Environment::NewLine + "After sorting with CompareOptions::None:"); - SortAndDisplay(wordList, CompareOptions::None); - - Console::WriteLine(Environment::NewLine + "After sorting with CompareOptions::StringSort:"); - SortAndDisplay(wordList, CompareOptions::StringSort); - } - -private: - static void SortAndDisplay(List^ unsorted, CompareOptions options) - { - // Create a copy of the original list to sort. - auto words = gcnew List(unsorted); - // Define the CompareInfo to use to compare strings. - CompareInfo^ comparer = CultureInfo::InvariantCulture->CompareInfo; - - // Sort the copy with the supplied CompareOptions then display. - words->Sort(gcnew Comparison([comparer, options](String^ str1, String^ str2) { - return comparer->Compare(str1, str2, options); - })); - - for each (String^ word in words) - { - Console::WriteLine(word); - } - } -}; - -int main(array ^args) -{ - StringSort::Main(); - return 0; -} - -/* -CompareOptions.None and CompareOptions.StringSort provide identical ordering by default -in .NET 5 and later, but in prior versions, the output will be the following: - -Before sorting: -cant -bill's -coop -cannot -billet -can't -con -bills -co-op - -After sorting with CompareOptions.None: -billet -bills -bill's -cannot -cant -can't -con -coop -co-op - -After sorting with CompareOptions.StringSort: -bill's -billet -bills -can't -cannot -cant -co-op -con -coop -*/ -// diff --git a/snippets/visualbasic/VS_Snippets_CLR_System/system.Globalization.CompareOptions.Values/VB/compareoptions_values.vb b/snippets/visualbasic/VS_Snippets_CLR_System/system.Globalization.CompareOptions.Values/VB/compareoptions_values.vb deleted file mode 100644 index 885a8c140fe..00000000000 --- a/snippets/visualbasic/VS_Snippets_CLR_System/system.Globalization.CompareOptions.Values/VB/compareoptions_values.vb +++ /dev/null @@ -1,90 +0,0 @@ -Imports System -Imports System.Globalization - -Module CompareOptionsExample - Sub Main() - ' Uppercase and lowercase characters are equivalent (according to the culture rules) - ' when IgnoreCase is used. - TestStringEquality("ONE two", "one TWO", "Case sensitivity", CompareOptions.IgnoreCase) - - ' Punctuation is ignored with the IgnoreSymbols option. - TestStringEquality("hello world", "hello, world!", "Punctuation", CompareOptions.IgnoreSymbols) - - ' Whitespace and mathematical symbols are also ignored with IgnoreSymbols. - TestStringEquality("3 + 5 = 8", "358", "Whitespace and mathematical symbols", CompareOptions.IgnoreSymbols) - - ' Caution: currency symbols and thousands separators are ignored with IgnoreSymbols. - ' Parse strings containing numbers/currency and compare them numerically instead. - TestStringEquality("Total $15,000", "Total: £150.00", "Currency symbols, decimals and thousands separators", CompareOptions.IgnoreSymbols) - - ' Full width characters are common in East Asian languages. Use the IgnoreWidth - ' option to treat full- and half-width characters as equal. - TestStringEquality("abc,-", "abc,-", "Half width and full width characters", CompareOptions.IgnoreWidth) - - ' The same string in Hiragana and Katakana is equal when IgnoreKanaType is used. - TestStringEquality("ありがとう", "アリガトウ", "Hiragana and Katakana strings", CompareOptions.IgnoreKanaType) - - ' When comparing with the IgnoreNonSpace option, characters like diacritical marks are ignored. - TestStringEquality("café", "cafe", "Diacritical marks", CompareOptions.IgnoreNonSpace) - - ' Ligature characters and their non-ligature forms compare equal with the IgnoreNonSpace option. - ' Note: prior to .NET 5, ligature characters were equal to their expanded forms by default. - TestStringEquality("straße œuvre cæsar", "strasse oeuvre caesar", "Ligature characters", CompareOptions.IgnoreNonSpace) - End Sub - - Private Sub TestStringEquality(str1 As String, str2 As String, description As String, options As CompareOptions) - Console.WriteLine(Environment.NewLine & description & ":") - ' First test with the default CompareOptions then with the provided options - TestStringEqualityWithOptions(str1, str2, CompareOptions.None) - TestStringEqualityWithOptions(str1, str2, options) - End Sub - - Private Sub TestStringEqualityWithOptions(str1 As String, str2 As String, options As CompareOptions) - Console.Write($" When using CompareOptions.{options}, ""{str1}"" and ""{str2}"" are ") - If String.Compare(str1, str2, CultureInfo.InvariantCulture, options) <> 0 Then - Console.Write("not ") - End If - Console.WriteLine("equal.") - End Sub -End Module - -' In .NET 5 and later, the output is the following: -' -'Case sensitivity : -' When using CompareOptions.None, "ONE two" and "one TWO" are not equal. -' When using CompareOptions.IgnoreCase, "ONE two" and "one TWO" are equal. -' -'Punctuation: -' When using CompareOptions.None, "hello world" and "hello, world!" are not equal. -' When using CompareOptions.IgnoreSymbols, "hello world" and "hello, world!" are equal. -' -'Whitespace And mathematical symbols: -' When using CompareOptions.None, "3 + 5 = 8" and "358" are not equal. -' When using CompareOptions.IgnoreSymbols, "3 + 5 = 8" and "358" are equal. -' -'Currency symbols, decimals And thousands separators: -' When using CompareOptions.None, "Total $15,000" and "Total: £150.00" are not equal. -' When using CompareOptions.IgnoreSymbols, "Total $15,000" and "Total: £150.00" are equal. -' -'Half width And full width characters: -' When using CompareOptions.None, "abc,-" and "abc,-" are not equal. -' When using CompareOptions.IgnoreWidth, "abc,-" and "abc,-" are equal. -' -'Hiragana And Katakana strings: -' When using CompareOptions.None, "ありがとう" and "アリガトウ" are not equal. -' When using CompareOptions.IgnoreKanaType, "ありがとう" and "アリガトウ" are equal. -' -'Diacritical marks : -' When using CompareOptions.None, "café" and "cafe" are not equal. -' When using CompareOptions.IgnoreNonSpace, "café" and "cafe" are equal. -' -'Ligature characters : -' When using CompareOptions.None, "straße œuvre cæsar" and "strasse oeuvre caesar" are not equal. -' When using CompareOptions.IgnoreNonSpace, "straße œuvre cæsar" and "strasse oeuvre caesar" are equal. -' -' Note: when using .NET versions prior to .NET 5, ligature characters compare as equal to their -' non-ligature counterparts by default, so the last test will output as follows: -' -'Ligature characters : -' When using CompareOptions.None, "straße œuvre cæsar" and "strasse oeuvre caesar" are equal. -' When using CompareOptions.IgnoreNonSpace, "straße œuvre cæsar" and "strasse oeuvre caesar" are equal. From 1c0e9427f6723d7b5e49e059c1dac19613692209 Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Wed, 2 Apr 2025 18:40:55 -0700 Subject: [PATCH 14/16] Revert "delete c++ snippets" This reverts commit 853b27b34c454801e29bac753a7aa91fc48a9d99. --- .../CPP/compareoptions_stringsort.cpp | 94 +++++++++++++++++++ .../VB/compareoptions_values.vb | 90 ++++++++++++++++++ 2 files changed, 184 insertions(+) create mode 100644 snippets/cpp/VS_Snippets_CLR_System/system.Globalization.CompareOptions.StringSort/CPP/compareoptions_stringsort.cpp create mode 100644 snippets/visualbasic/VS_Snippets_CLR_System/system.Globalization.CompareOptions.Values/VB/compareoptions_values.vb diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Globalization.CompareOptions.StringSort/CPP/compareoptions_stringsort.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Globalization.CompareOptions.StringSort/CPP/compareoptions_stringsort.cpp new file mode 100644 index 00000000000..02d0766c4fe --- /dev/null +++ b/snippets/cpp/VS_Snippets_CLR_System/system.Globalization.CompareOptions.StringSort/CPP/compareoptions_stringsort.cpp @@ -0,0 +1,94 @@ +// +#include +#using + +using namespace System; +using namespace System::Collections::Generic; +using namespace System::Globalization; + +ref class StringSort +{ +public: + static void Main() + { + auto wordList = gcnew List { + "cant", "bill's", "coop", "cannot", "billet", "can't", "con", "bills", "co-op" + }; + + Console::WriteLine("Before sorting:"); + for each (String^ word in wordList) + { + Console::WriteLine(word); + } + + Console::WriteLine(Environment::NewLine + "After sorting with CompareOptions::None:"); + SortAndDisplay(wordList, CompareOptions::None); + + Console::WriteLine(Environment::NewLine + "After sorting with CompareOptions::StringSort:"); + SortAndDisplay(wordList, CompareOptions::StringSort); + } + +private: + static void SortAndDisplay(List^ unsorted, CompareOptions options) + { + // Create a copy of the original list to sort. + auto words = gcnew List(unsorted); + // Define the CompareInfo to use to compare strings. + CompareInfo^ comparer = CultureInfo::InvariantCulture->CompareInfo; + + // Sort the copy with the supplied CompareOptions then display. + words->Sort(gcnew Comparison([comparer, options](String^ str1, String^ str2) { + return comparer->Compare(str1, str2, options); + })); + + for each (String^ word in words) + { + Console::WriteLine(word); + } + } +}; + +int main(array ^args) +{ + StringSort::Main(); + return 0; +} + +/* +CompareOptions.None and CompareOptions.StringSort provide identical ordering by default +in .NET 5 and later, but in prior versions, the output will be the following: + +Before sorting: +cant +bill's +coop +cannot +billet +can't +con +bills +co-op + +After sorting with CompareOptions.None: +billet +bills +bill's +cannot +cant +can't +con +coop +co-op + +After sorting with CompareOptions.StringSort: +bill's +billet +bills +can't +cannot +cant +co-op +con +coop +*/ +// diff --git a/snippets/visualbasic/VS_Snippets_CLR_System/system.Globalization.CompareOptions.Values/VB/compareoptions_values.vb b/snippets/visualbasic/VS_Snippets_CLR_System/system.Globalization.CompareOptions.Values/VB/compareoptions_values.vb new file mode 100644 index 00000000000..885a8c140fe --- /dev/null +++ b/snippets/visualbasic/VS_Snippets_CLR_System/system.Globalization.CompareOptions.Values/VB/compareoptions_values.vb @@ -0,0 +1,90 @@ +Imports System +Imports System.Globalization + +Module CompareOptionsExample + Sub Main() + ' Uppercase and lowercase characters are equivalent (according to the culture rules) + ' when IgnoreCase is used. + TestStringEquality("ONE two", "one TWO", "Case sensitivity", CompareOptions.IgnoreCase) + + ' Punctuation is ignored with the IgnoreSymbols option. + TestStringEquality("hello world", "hello, world!", "Punctuation", CompareOptions.IgnoreSymbols) + + ' Whitespace and mathematical symbols are also ignored with IgnoreSymbols. + TestStringEquality("3 + 5 = 8", "358", "Whitespace and mathematical symbols", CompareOptions.IgnoreSymbols) + + ' Caution: currency symbols and thousands separators are ignored with IgnoreSymbols. + ' Parse strings containing numbers/currency and compare them numerically instead. + TestStringEquality("Total $15,000", "Total: £150.00", "Currency symbols, decimals and thousands separators", CompareOptions.IgnoreSymbols) + + ' Full width characters are common in East Asian languages. Use the IgnoreWidth + ' option to treat full- and half-width characters as equal. + TestStringEquality("abc,-", "abc,-", "Half width and full width characters", CompareOptions.IgnoreWidth) + + ' The same string in Hiragana and Katakana is equal when IgnoreKanaType is used. + TestStringEquality("ありがとう", "アリガトウ", "Hiragana and Katakana strings", CompareOptions.IgnoreKanaType) + + ' When comparing with the IgnoreNonSpace option, characters like diacritical marks are ignored. + TestStringEquality("café", "cafe", "Diacritical marks", CompareOptions.IgnoreNonSpace) + + ' Ligature characters and their non-ligature forms compare equal with the IgnoreNonSpace option. + ' Note: prior to .NET 5, ligature characters were equal to their expanded forms by default. + TestStringEquality("straße œuvre cæsar", "strasse oeuvre caesar", "Ligature characters", CompareOptions.IgnoreNonSpace) + End Sub + + Private Sub TestStringEquality(str1 As String, str2 As String, description As String, options As CompareOptions) + Console.WriteLine(Environment.NewLine & description & ":") + ' First test with the default CompareOptions then with the provided options + TestStringEqualityWithOptions(str1, str2, CompareOptions.None) + TestStringEqualityWithOptions(str1, str2, options) + End Sub + + Private Sub TestStringEqualityWithOptions(str1 As String, str2 As String, options As CompareOptions) + Console.Write($" When using CompareOptions.{options}, ""{str1}"" and ""{str2}"" are ") + If String.Compare(str1, str2, CultureInfo.InvariantCulture, options) <> 0 Then + Console.Write("not ") + End If + Console.WriteLine("equal.") + End Sub +End Module + +' In .NET 5 and later, the output is the following: +' +'Case sensitivity : +' When using CompareOptions.None, "ONE two" and "one TWO" are not equal. +' When using CompareOptions.IgnoreCase, "ONE two" and "one TWO" are equal. +' +'Punctuation: +' When using CompareOptions.None, "hello world" and "hello, world!" are not equal. +' When using CompareOptions.IgnoreSymbols, "hello world" and "hello, world!" are equal. +' +'Whitespace And mathematical symbols: +' When using CompareOptions.None, "3 + 5 = 8" and "358" are not equal. +' When using CompareOptions.IgnoreSymbols, "3 + 5 = 8" and "358" are equal. +' +'Currency symbols, decimals And thousands separators: +' When using CompareOptions.None, "Total $15,000" and "Total: £150.00" are not equal. +' When using CompareOptions.IgnoreSymbols, "Total $15,000" and "Total: £150.00" are equal. +' +'Half width And full width characters: +' When using CompareOptions.None, "abc,-" and "abc,-" are not equal. +' When using CompareOptions.IgnoreWidth, "abc,-" and "abc,-" are equal. +' +'Hiragana And Katakana strings: +' When using CompareOptions.None, "ありがとう" and "アリガトウ" are not equal. +' When using CompareOptions.IgnoreKanaType, "ありがとう" and "アリガトウ" are equal. +' +'Diacritical marks : +' When using CompareOptions.None, "café" and "cafe" are not equal. +' When using CompareOptions.IgnoreNonSpace, "café" and "cafe" are equal. +' +'Ligature characters : +' When using CompareOptions.None, "straße œuvre cæsar" and "strasse oeuvre caesar" are not equal. +' When using CompareOptions.IgnoreNonSpace, "straße œuvre cæsar" and "strasse oeuvre caesar" are equal. +' +' Note: when using .NET versions prior to .NET 5, ligature characters compare as equal to their +' non-ligature counterparts by default, so the last test will output as follows: +' +'Ligature characters : +' When using CompareOptions.None, "straße œuvre cæsar" and "strasse oeuvre caesar" are equal. +' When using CompareOptions.IgnoreNonSpace, "straße œuvre cæsar" and "strasse oeuvre caesar" are equal. From 4fce14eff8b56fa7e2063780d9a4cb48bf2c835d Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Wed, 2 Apr 2025 18:42:13 -0700 Subject: [PATCH 15/16] delete c++ snippets --- .../CPP/compareoptions_stringsort.cpp | 94 --------------- .../CPP/compareoptions_values.cpp | 111 ------------------ 2 files changed, 205 deletions(-) delete mode 100644 snippets/cpp/VS_Snippets_CLR_System/system.Globalization.CompareOptions.StringSort/CPP/compareoptions_stringsort.cpp delete mode 100644 snippets/cpp/VS_Snippets_CLR_System/system.Globalization.CompareOptions.Values/CPP/compareoptions_values.cpp diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Globalization.CompareOptions.StringSort/CPP/compareoptions_stringsort.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Globalization.CompareOptions.StringSort/CPP/compareoptions_stringsort.cpp deleted file mode 100644 index 02d0766c4fe..00000000000 --- a/snippets/cpp/VS_Snippets_CLR_System/system.Globalization.CompareOptions.StringSort/CPP/compareoptions_stringsort.cpp +++ /dev/null @@ -1,94 +0,0 @@ -// -#include -#using - -using namespace System; -using namespace System::Collections::Generic; -using namespace System::Globalization; - -ref class StringSort -{ -public: - static void Main() - { - auto wordList = gcnew List { - "cant", "bill's", "coop", "cannot", "billet", "can't", "con", "bills", "co-op" - }; - - Console::WriteLine("Before sorting:"); - for each (String^ word in wordList) - { - Console::WriteLine(word); - } - - Console::WriteLine(Environment::NewLine + "After sorting with CompareOptions::None:"); - SortAndDisplay(wordList, CompareOptions::None); - - Console::WriteLine(Environment::NewLine + "After sorting with CompareOptions::StringSort:"); - SortAndDisplay(wordList, CompareOptions::StringSort); - } - -private: - static void SortAndDisplay(List^ unsorted, CompareOptions options) - { - // Create a copy of the original list to sort. - auto words = gcnew List(unsorted); - // Define the CompareInfo to use to compare strings. - CompareInfo^ comparer = CultureInfo::InvariantCulture->CompareInfo; - - // Sort the copy with the supplied CompareOptions then display. - words->Sort(gcnew Comparison([comparer, options](String^ str1, String^ str2) { - return comparer->Compare(str1, str2, options); - })); - - for each (String^ word in words) - { - Console::WriteLine(word); - } - } -}; - -int main(array ^args) -{ - StringSort::Main(); - return 0; -} - -/* -CompareOptions.None and CompareOptions.StringSort provide identical ordering by default -in .NET 5 and later, but in prior versions, the output will be the following: - -Before sorting: -cant -bill's -coop -cannot -billet -can't -con -bills -co-op - -After sorting with CompareOptions.None: -billet -bills -bill's -cannot -cant -can't -con -coop -co-op - -After sorting with CompareOptions.StringSort: -bill's -billet -bills -can't -cannot -cant -co-op -con -coop -*/ -// diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Globalization.CompareOptions.Values/CPP/compareoptions_values.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Globalization.CompareOptions.Values/CPP/compareoptions_values.cpp deleted file mode 100644 index ef6239d58e9..00000000000 --- a/snippets/cpp/VS_Snippets_CLR_System/system.Globalization.CompareOptions.Values/CPP/compareoptions_values.cpp +++ /dev/null @@ -1,111 +0,0 @@ -// -#include -#include - -using namespace System; -using namespace System::Globalization; - -public ref class CompareOptionsExample -{ -public: - static void Main() - { - // Uppercase and lowercase characters are equivalent (according to the culture rules) - // when IgnoreCase is used. - TestStringEquality("ONE two", "one TWO", "Case sensitivity", CompareOptions::IgnoreCase); - - // Punctuation is ignored with the IgnoreSymbols option. - TestStringEquality("hello world", "hello, world!", "Punctuation", CompareOptions::IgnoreSymbols); - - // Whitespace and mathematical symbols are also ignored with IgnoreSymbols. - TestStringEquality("3 + 5 = 8", "358", "Whitespace and mathematical symbols", CompareOptions::IgnoreSymbols); - - // Caution: currency symbols and thousands separators are ignored with IgnoreSymbols. - // Parse strings containing numbers/currency and compare them numerically instead. - TestStringEquality("Total $15,000", "Total: £150.00", "Currency symbols, decimals and thousands separators", CompareOptions::IgnoreSymbols); - - // Full width characters are common in East Asian languages. Use the IgnoreWidth - // option to treat full- and half-width characters as equal. - TestStringEquality("abc,-", "abc,-", "Half width and full width characters", CompareOptions::IgnoreWidth); - - // The same string in Hiragana and Katakana is equal when IgnoreKanaType is used. - TestStringEquality("ありがとう", "アリガトウ", "Hiragana and Katakana strings", CompareOptions::IgnoreKanaType); - - // When comparing with the IgnoreNonSpace option, characters like diacritical marks are ignored. - TestStringEquality("café", "cafe", "Diacritical marks", CompareOptions::IgnoreNonSpace); - - // Ligature characters and their non-ligature forms compare equal with the IgnoreNonSpace option. - // Note: prior to .NET 5, ligature characters were equal to their expanded forms by default. - TestStringEquality("straße œuvre cæsar", "strasse oeuvre caesar", "Ligature characters", CompareOptions::IgnoreNonSpace); - } - -private: - static void TestStringEquality(String^ str1, String^ str2, String^ description, CompareOptions options) - { - Console::WriteLine(Environment::NewLine + description + ":"); - // First test with the default CompareOptions then with the provided options - TestStringEquality(str1, str2, CompareOptions::None); - TestStringEquality(str1, str2, options); - } - - static void TestStringEquality(String^ str1, String^ str2, CompareOptions options) - { - Console::Write(" When using CompareOptions." + options + ", \"" + str1 + "\" and \"" + str2 + "\" are "); - if (String::Compare(str1, str2, CultureInfo::InvariantCulture, options) != 0) - { - Console::Write("not "); - } - Console::WriteLine("equal."); - } -}; - -int main(array ^args) -{ - CompareOptionsExample::Main(); - return 0; -} - -/* -In .NET 5 and later, the output will be the following: - -Case sensitivity: - When using CompareOptions.None, "ONE two" and "one TWO" are not equal. - When using CompareOptions.IgnoreCase, "ONE two" and "one TWO" are equal. - -Punctuation: - When using CompareOptions.None, "hello world" and "hello, world!" are not equal. - When using CompareOptions.IgnoreSymbols, "hello world" and "hello, world!" are equal. - -Whitespace and mathematical symbols: - When using CompareOptions.None, "3 + 5 = 8" and "358" are not equal. - When using CompareOptions.IgnoreSymbols, "3 + 5 = 8" and "358" are equal. - -Currency symbols, decimals and thousands separators: - When using CompareOptions.None, "Total $15,000" and "Total: £150.00" are not equal. - When using CompareOptions.IgnoreSymbols, "Total $15,000" and "Total: £150.00" are equal. - -Half width and full width characters: - When using CompareOptions.None, "abc,-" and "abc,-" are not equal. - When using CompareOptions.IgnoreWidth, "abc,-" and "abc,-" are equal. - -Hiragana and Katakana strings: - When using CompareOptions.None, "ありがとう" and "アリガトウ" are not equal. - When using CompareOptions.IgnoreKanaType, "ありがとう" and "アリガトウ" are equal. - -Diacritical marks: - When using CompareOptions.None, "café" and "cafe" are not equal. - When using CompareOptions.IgnoreNonSpace, "café" and "cafe" are equal. - -Ligature characters: - When using CompareOptions.None, "straße œuvre cæsar" and "strasse oeuvre caesar" are not equal. - When using CompareOptions.IgnoreNonSpace, "straße œuvre cæsar" and "strasse oeuvre caesar" are equal. - - -Note: when using .NET versions prior to .NET 5, ligature characters compare as equal to their -non-ligature counterparts by default, so the last test will output as follows: - -Ligature characters: - When using CompareOptions.None, "straße œuvre cæsar" and "strasse oeuvre caesar" are equal. - When using CompareOptions.IgnoreNonSpace, "straße œuvre cæsar" and "strasse oeuvre caesar" are equal. -*/ -// From 448db5d89b271711b294976217ad804cf1e7f845 Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Wed, 2 Apr 2025 18:50:03 -0700 Subject: [PATCH 16/16] add module names --- .../fsharp/System.Globalization/compareoptions_stringsort.fs | 2 ++ snippets/fsharp/System.Globalization/compareoptions_values.fs | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/snippets/fsharp/System.Globalization/compareoptions_stringsort.fs b/snippets/fsharp/System.Globalization/compareoptions_stringsort.fs index 6b537c1bc1e..355c2d18ccf 100644 --- a/snippets/fsharp/System.Globalization/compareoptions_stringsort.fs +++ b/snippets/fsharp/System.Globalization/compareoptions_stringsort.fs @@ -1,3 +1,5 @@ +module compareoptions_stringsort + open System open System.Collections.Generic open System.Globalization diff --git a/snippets/fsharp/System.Globalization/compareoptions_values.fs b/snippets/fsharp/System.Globalization/compareoptions_values.fs index d6dc803a586..eb3a3529af5 100644 --- a/snippets/fsharp/System.Globalization/compareoptions_values.fs +++ b/snippets/fsharp/System.Globalization/compareoptions_values.fs @@ -1,4 +1,6 @@ -open System +module compareoptions_values + +open System open System.Globalization let testStringEquality (str1: string) (str2: string) (description: string) (options: CompareOptions) =