From 1471f24ee9d4998ccb996ce4224c4bf46ab2d272 Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Wed, 30 Jul 2025 11:44:59 -0700 Subject: [PATCH 1/3] fix remark about empty array --- .../System/String/IndexOfAny/IndexOfAny1.cs | 20 +++++++++---------- .../System/String/IndexOfAny/IndexOfAny1.fs | 5 +++-- .../System/String/IndexOfAny/IndexOfAny1.vb | 9 +++++---- xml/System/String.xml | 4 +++- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/snippets/csharp/System/String/IndexOfAny/IndexOfAny1.cs b/snippets/csharp/System/String/IndexOfAny/IndexOfAny1.cs index 1eb99e29e51..4eadaa33c85 100644 --- a/snippets/csharp/System/String/IndexOfAny/IndexOfAny1.cs +++ b/snippets/csharp/System/String/IndexOfAny/IndexOfAny1.cs @@ -1,19 +1,19 @@ -// -using System; +using System; public class Example { public static void Main() { - char[] chars = { 'a', 'e', 'i', 'o', 'u', 'y', + // + char[] chars = { 'a', 'e', 'i', 'o', 'u', 'y', 'A', 'E', 'I', 'O', 'U', 'Y' }; String s = "The long and winding road..."; - Console.WriteLine("The first vowel in \n {0}\nis found at position {1}", - s, s.IndexOfAny(chars) + 1); + Console.WriteLine($"The first vowel in \n {s}\nis found at index {s.IndexOfAny(chars)}"); + + // The example displays the following output: + // The first vowel in + // The long and winding road... + // is found at index 2 + // } } -// The example displays the following output: -// The first vowel in -// The long and winding road... -// is found at position 3 -// diff --git a/snippets/fsharp/System/String/IndexOfAny/IndexOfAny1.fs b/snippets/fsharp/System/String/IndexOfAny/IndexOfAny1.fs index d3befcd62c6..2dbdf7c7412 100644 --- a/snippets/fsharp/System/String/IndexOfAny/IndexOfAny1.fs +++ b/snippets/fsharp/System/String/IndexOfAny/IndexOfAny1.fs @@ -3,9 +3,10 @@ module IndexOfAny1.fs let chars = [| 'a'; 'e'; 'i'; 'o'; 'u'; 'y' 'A'; 'E'; 'I'; 'O'; 'U'; 'Y' |] let s = "The long and winding road..." -printfn $"The first vowel in \n {s}\nis found at position {s.IndexOfAny chars + 1}" +printfn $"The first vowel in \n {s}\nis found at position {s.IndexOfAny chars}" + // The example displays the following output: // The first vowel in // The long and winding road... -// is found at position 3 +// is found at index 2 // diff --git a/snippets/visualbasic/System/String/IndexOfAny/IndexOfAny1.vb b/snippets/visualbasic/System/String/IndexOfAny/IndexOfAny1.vb index 0a1581ecbfa..c129ddf3487 100644 --- a/snippets/visualbasic/System/String/IndexOfAny/IndexOfAny1.vb +++ b/snippets/visualbasic/System/String/IndexOfAny/IndexOfAny1.vb @@ -4,15 +4,16 @@ Option Strict On ' Module Example Public Sub Main() - Dim chars() As Char = { "a"c, "e"c, "i"c, "o"c, "u"c, "y"c, + Dim chars() As Char = { "a"c, "e"c, "i"c, "o"c, "u"c, "y"c, "A"c, "E"c, "I"c, "O"c, "U"c, "Y"c } Dim s As String = "The long and winding road..." - Console.WriteLine("The first vowel in {2} {0}{2}is found at position {1}", - s, s.IndexOfAny(chars) + 1, vbCrLf) + Console.WriteLine("The first vowel in {2} {0}{2}is found at index {1}", + s, s.IndexOfAny(chars), vbCrLf) End Sub End Module + ' The example displays the following output: ' The first vowel in ' The long and winding road... -' is found at position 3 +' is found at index 2 ' diff --git a/xml/System/String.xml b/xml/System/String.xml index ab5c9e61be2..9a58edaead8 100644 --- a/xml/System/String.xml +++ b/xml/System/String.xml @@ -7846,13 +7846,15 @@ In the following example, the method, where a Unicode scalar value representing a precomposed character, such as the ligature "Æ" (U+00C6), might be considered equivalent to any occurrence of the character's components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture. ## Examples + The following example finds the first vowel in a string. :::code language="csharp" source="~/snippets/csharp/System/String/IndexOfAny/IndexOfAny1.cs" interactive="try-dotnet" id="Snippet1"::: From 4111d497681013299279a5789453a3a6eba664ab Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Wed, 30 Jul 2025 11:46:49 -0700 Subject: [PATCH 2/3] index --- snippets/fsharp/System/String/IndexOfAny/IndexOfAny1.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/fsharp/System/String/IndexOfAny/IndexOfAny1.fs b/snippets/fsharp/System/String/IndexOfAny/IndexOfAny1.fs index 2dbdf7c7412..e34a4452b8b 100644 --- a/snippets/fsharp/System/String/IndexOfAny/IndexOfAny1.fs +++ b/snippets/fsharp/System/String/IndexOfAny/IndexOfAny1.fs @@ -3,7 +3,7 @@ module IndexOfAny1.fs let chars = [| 'a'; 'e'; 'i'; 'o'; 'u'; 'y' 'A'; 'E'; 'I'; 'O'; 'U'; 'Y' |] let s = "The long and winding road..." -printfn $"The first vowel in \n {s}\nis found at position {s.IndexOfAny chars}" +printfn $"The first vowel in \n {s}\nis found at index {s.IndexOfAny chars}" // The example displays the following output: // The first vowel in From 2b9cfbe97fbf97f6500711adada4a8b5e2ea6995 Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Wed, 30 Jul 2025 13:27:49 -0700 Subject: [PATCH 3/3] add missing project files --- .../System/String/IndexOfAny/IndexOfAny1.cs | 7 +- .../System/String/IndexOfAny/Program.cs | 18 +++++ .../System/String/IndexOfAny/Project.csproj | 8 +++ .../csharp/System/String/IndexOfAny/ixany2.cs | 71 ++++++++++--------- .../csharp/System/String/IndexOfAny/ixany3.cs | 71 ++++++++++--------- .../System/String/IndexOfAny/IndexOfAny1.vb | 4 +- .../System/String/IndexOfAny/Project.vbproj | 8 +++ .../System/String/IndexOfAny/ixany2.vb | 8 +-- .../System/String/IndexOfAny/ixany3.vb | 10 +-- 9 files changed, 126 insertions(+), 79 deletions(-) create mode 100644 snippets/csharp/System/String/IndexOfAny/Program.cs create mode 100644 snippets/csharp/System/String/IndexOfAny/Project.csproj create mode 100644 snippets/visualbasic/System/String/IndexOfAny/Project.vbproj diff --git a/snippets/csharp/System/String/IndexOfAny/IndexOfAny1.cs b/snippets/csharp/System/String/IndexOfAny/IndexOfAny1.cs index 4eadaa33c85..bd5da47b4d8 100644 --- a/snippets/csharp/System/String/IndexOfAny/IndexOfAny1.cs +++ b/snippets/csharp/System/String/IndexOfAny/IndexOfAny1.cs @@ -1,14 +1,15 @@ using System; -public class Example +public class Example1 { - public static void Main() + public static void Run() { // char[] chars = { 'a', 'e', 'i', 'o', 'u', 'y', 'A', 'E', 'I', 'O', 'U', 'Y' }; String s = "The long and winding road..."; - Console.WriteLine($"The first vowel in \n {s}\nis found at index {s.IndexOfAny(chars)}"); + Console.WriteLine($"The first vowel in \n {s}\n" + + $"is found at index {s.IndexOfAny(chars)}"); // The example displays the following output: // The first vowel in diff --git a/snippets/csharp/System/String/IndexOfAny/Program.cs b/snippets/csharp/System/String/IndexOfAny/Program.cs new file mode 100644 index 00000000000..510edb4cb58 --- /dev/null +++ b/snippets/csharp/System/String/IndexOfAny/Program.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Project +{ + internal class Program + { + static void Main(string[] args) + { + Example1.Run(); + Example2.Run(); + Example3.Run(); + } + } +} diff --git a/snippets/csharp/System/String/IndexOfAny/Project.csproj b/snippets/csharp/System/String/IndexOfAny/Project.csproj new file mode 100644 index 00000000000..92e46ddaccf --- /dev/null +++ b/snippets/csharp/System/String/IndexOfAny/Project.csproj @@ -0,0 +1,8 @@ + + + + Exe + net9.0 + + + diff --git a/snippets/csharp/System/String/IndexOfAny/ixany2.cs b/snippets/csharp/System/String/IndexOfAny/ixany2.cs index 7a399ceb525..4bd096b2703 100644 --- a/snippets/csharp/System/String/IndexOfAny/ixany2.cs +++ b/snippets/csharp/System/String/IndexOfAny/ixany2.cs @@ -1,41 +1,48 @@ -// + // Sample for String.IndexOfAny(Char[], Int32) using System; -class Sample { - public static void Main() +class Example2 +{ + public static void Run() { - string br1 = "0----+----1----+----2----+----3----+----4----+----5----+----6----+-"; - string br2 = "0123456789012345678901234567890123456789012345678901234567890123456"; - string str = "Now is the time for all good men to come to the aid of their party."; - int start; - int at; - string target = "is"; - char[] anyOf = target.ToCharArray(); + // + string br1 = "0----+----1----+----2----+----3" + + "----+----4----+----5----+----6----+-"; + string br2 = "012345678901234567890123456789" + + "0123456789012345678901234567890123456"; + string str = "Now is the time for all good men " + + "to come to the aid of their party."; + int start; + int at; + string target = "is"; + char[] anyOf = target.ToCharArray(); - start = str.Length/2; - Console.WriteLine(); - Console.WriteLine("The first character occurrence from position {0} to {1}.", - start, str.Length-1); - Console.WriteLine("{1}{0}{2}{0}{3}{0}", Environment.NewLine, br1, br2, str); - Console.Write("A character in '{0}' occurs at position: ", target); + start = str.Length / 2; + Console.WriteLine(); + Console.WriteLine("The first character occurrence " + + $"from position {start} to {str.Length - 1}:"); + Console.WriteLine($"{Environment.NewLine}{br1}{Environment.NewLine}" + + $"{br2}{Environment.NewLine}{str}{Environment.NewLine}"); + Console.Write($"A character in '{target}' occurs at position: "); - at = str.IndexOfAny(anyOf, start); - if (at > -1) - Console.Write(at); - else - Console.Write("(not found)"); - Console.WriteLine(); - } -} -/* + at = str.IndexOfAny(anyOf, start); + if (at > -1) + Console.Write(at); + else + Console.Write("(not found)"); + Console.WriteLine(); + + /* -The first character occurrence from position 33 to 66. -0----+----1----+----2----+----3----+----4----+----5----+----6----+- -0123456789012345678901234567890123456789012345678901234567890123456 -Now is the time for all good men to come to the aid of their party. + The first character occurrence from position 33 to 66. + 0----+----1----+----2----+----3----+----4----+----5----+----6----+- + 0123456789012345678901234567890123456789012345678901234567890123456 + Now is the time for all good men to come to the aid of their party. -A character in 'is' occurs at position: 49 + A character in 'is' occurs at position: 49 -*/ -// \ No newline at end of file + */ + // + } +} diff --git a/snippets/csharp/System/String/IndexOfAny/ixany3.cs b/snippets/csharp/System/String/IndexOfAny/ixany3.cs index c27e35f20ce..cd33a33b681 100644 --- a/snippets/csharp/System/String/IndexOfAny/ixany3.cs +++ b/snippets/csharp/System/String/IndexOfAny/ixany3.cs @@ -1,42 +1,47 @@ -// + // Sample for String.IndexOfAny(Char[], Int32, Int32) using System; -class Sample { - public static void Main() +class Example3 +{ + public static void Run() { - string br1 = "0----+----1----+----2----+----3----+----4----+----5----+----6----+-"; - string br2 = "0123456789012345678901234567890123456789012345678901234567890123456"; - string str = "Now is the time for all good men to come to the aid of their party."; - int start; - int at; - int count; - string target = "aid"; - char[] anyOf = target.ToCharArray(); + // + string br1 = "0----+----1----+----2----+----3----" + + "+----4----+----5----+----6----+-"; + string br2 = "012345678901234567890123456789" + + "0123456789012345678901234567890123456"; + string str = "Now is the time for all good men " + + "to come to the aid of their party."; + string target = "aid"; + char[] anyOf = target.ToCharArray(); - start = (str.Length-1)/3; - count = (str.Length-1)/4; - Console.WriteLine(); - Console.WriteLine("The first character occurrence from position {0} for {1} characters.", start, count); - Console.WriteLine("{1}{0}{2}{0}{3}{0}", Environment.NewLine, br1, br2, str); - Console.Write("A character in '{0}' occurs at position: ", target); + int start = (str.Length - 1) / 3; + int count = (str.Length - 1) / 4; + Console.WriteLine(); + Console.WriteLine("The first character occurrence from " + + $"position {start} for {count} characters:"); + Console.WriteLine($"{Environment.NewLine}{br1}{Environment.NewLine}{br2}" + + $"{Environment.NewLine}{str}{Environment.NewLine}"); + Console.Write($"A character in '{target}' occurs at position: "); - at = str.IndexOfAny(anyOf, start, count); - if (at > -1) - Console.Write(at); - else - Console.Write("(not found)"); - Console.WriteLine(); - } -} -/* + int at = str.IndexOfAny(anyOf, start, count); + if (at > -1) + Console.Write(at); + else + Console.Write("(not found)"); + Console.WriteLine(); + + /* -The first character occurrence from position 22 for 16 characters. -0----+----1----+----2----+----3----+----4----+----5----+----6----+- -0123456789012345678901234567890123456789012345678901234567890123456 -Now is the time for all good men to come to the aid of their party. + The first character occurrence from position 22 for 16 characters. + 0----+----1----+----2----+----3----+----4----+----5----+----6----+- + 0123456789012345678901234567890123456789012345678901234567890123456 + Now is the time for all good men to come to the aid of their party. -A character in 'aid' occurs at position: 27 + A character in 'aid' occurs at position: 27 -*/ -// \ No newline at end of file + */ + // + } +} diff --git a/snippets/visualbasic/System/String/IndexOfAny/IndexOfAny1.vb b/snippets/visualbasic/System/String/IndexOfAny/IndexOfAny1.vb index c129ddf3487..aca80089a4b 100644 --- a/snippets/visualbasic/System/String/IndexOfAny/IndexOfAny1.vb +++ b/snippets/visualbasic/System/String/IndexOfAny/IndexOfAny1.vb @@ -2,8 +2,8 @@ Option Strict On ' -Module Example - Public Sub Main() +Module Example1 + Public Sub Run() Dim chars() As Char = { "a"c, "e"c, "i"c, "o"c, "u"c, "y"c, "A"c, "E"c, "I"c, "O"c, "U"c, "Y"c } Dim s As String = "The long and winding road..." diff --git a/snippets/visualbasic/System/String/IndexOfAny/Project.vbproj b/snippets/visualbasic/System/String/IndexOfAny/Project.vbproj new file mode 100644 index 00000000000..fc3f09ab482 --- /dev/null +++ b/snippets/visualbasic/System/String/IndexOfAny/Project.vbproj @@ -0,0 +1,8 @@ + + + + Library + net9.0 + + + diff --git a/snippets/visualbasic/System/String/IndexOfAny/ixany2.vb b/snippets/visualbasic/System/String/IndexOfAny/ixany2.vb index 23726e70268..777ad43102b 100644 --- a/snippets/visualbasic/System/String/IndexOfAny/ixany2.vb +++ b/snippets/visualbasic/System/String/IndexOfAny/ixany2.vb @@ -1,7 +1,7 @@ ' ' Sample for String.IndexOfAny(Char[], Int32) -Class Sample - Public Shared Sub Main() +Class Example2 + Public Shared Sub Run() Dim br1 As String = "0----+----1----+----2----+----3----+----4----+----5----+----6----+-" Dim br2 As String = "0123456789012345678901234567890123456789012345678901234567890123456" Dim str As String = "Now is the time for all good men to come to the aid of their party." @@ -9,7 +9,7 @@ Class Sample Dim at As Integer Dim target As String = "is" Dim anyOf As Char() = target.ToCharArray() - + start = str.Length / 2 Console.WriteLine() Console.WriteLine("Search for a character occurrence from position {0} to {1}.", _ @@ -34,4 +34,4 @@ End Class ' 'A character in 'is' occurs at position: 49 ' -' \ No newline at end of file +' diff --git a/snippets/visualbasic/System/String/IndexOfAny/ixany3.vb b/snippets/visualbasic/System/String/IndexOfAny/ixany3.vb index 7bb5588b4cb..e1510f5d7df 100644 --- a/snippets/visualbasic/System/String/IndexOfAny/ixany3.vb +++ b/snippets/visualbasic/System/String/IndexOfAny/ixany3.vb @@ -1,7 +1,7 @@ ' ' Sample for String.IndexOfAny(Char[], Int32, Int32) -Class Sample - Public Shared Sub Main() +Class Example3 + Public Shared Sub Run() Dim br1 As String = "0----+----1----+----2----+----3----+----4----+----5----+----6----+-" Dim br2 As String = "0123456789012345678901234567890123456789012345678901234567890123456" Dim str As String = "Now is the time for all good men to come to the aid of their party." @@ -10,14 +10,14 @@ Class Sample Dim count As Integer Dim target As String = "aid" Dim anyOf As Char() = target.ToCharArray() - + start =(str.Length - 1) / 3 count =(str.Length - 1) / 4 Console.WriteLine() Console.WriteLine("The first character occurrence from position {0} for {1} characters.", start, count) Console.WriteLine("{1}{0}{2}{0}{3}{0}", Environment.NewLine, br1, br2, str) Console.Write("A character in '{0}' occurs at position: ", target) - + at = str.IndexOfAny(anyOf, start, count) If at > - 1 Then Console.Write(at) @@ -35,4 +35,4 @@ End Class ' 'A character in 'aid' occurs at position: 27 ' -' \ No newline at end of file +'