Skip to content

Commit 4077c7e

Browse files
Merge pull request #11651 from dotnet/main
Merge main into live
2 parents 416a70b + 6a44eab commit 4077c7e

File tree

13 files changed

+151
-109
lines changed

13 files changed

+151
-109
lines changed

snippets/csharp/System/String/IndexOfAny/IndexOfAny1.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
// <Snippet1>
2-
using System;
1+
using System;
32

4-
public class Example
3+
public class Example1
54
{
6-
public static void Main()
5+
public static void Run()
76
{
8-
char[] chars = { 'a', 'e', 'i', 'o', 'u', 'y',
7+
// <Snippet1>
8+
char[] chars = { 'a', 'e', 'i', 'o', 'u', 'y',
99
'A', 'E', 'I', 'O', 'U', 'Y' };
1010
String s = "The long and winding road...";
11-
Console.WriteLine("The first vowel in \n {0}\nis found at position {1}",
12-
s, s.IndexOfAny(chars) + 1);
11+
Console.WriteLine($"The first vowel in \n {s}\n" +
12+
$"is found at index {s.IndexOfAny(chars)}");
13+
14+
// The example displays the following output:
15+
// The first vowel in
16+
// The long and winding road...
17+
// is found at index 2
18+
// </Snippet1>
1319
}
1420
}
15-
// The example displays the following output:
16-
// The first vowel in
17-
// The long and winding road...
18-
// is found at position 3
19-
// </Snippet1>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Project
8+
{
9+
internal class Program
10+
{
11+
static void Main(string[] args)
12+
{
13+
Example1.Run();
14+
Example2.Run();
15+
Example3.Run();
16+
}
17+
}
18+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net9.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
</Project>
Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,48 @@
1-
//<snippet1>
1+

22
// Sample for String.IndexOfAny(Char[], Int32)
33
using System;
44

5-
class Sample {
6-
public static void Main()
5+
class Example2
6+
{
7+
public static void Run()
78
{
8-
string br1 = "0----+----1----+----2----+----3----+----4----+----5----+----6----+-";
9-
string br2 = "0123456789012345678901234567890123456789012345678901234567890123456";
10-
string str = "Now is the time for all good men to come to the aid of their party.";
11-
int start;
12-
int at;
13-
string target = "is";
14-
char[] anyOf = target.ToCharArray();
9+
//<snippet1>
10+
string br1 = "0----+----1----+----2----+----3" +
11+
"----+----4----+----5----+----6----+-";
12+
string br2 = "012345678901234567890123456789" +
13+
"0123456789012345678901234567890123456";
14+
string str = "Now is the time for all good men " +
15+
"to come to the aid of their party.";
16+
int start;
17+
int at;
18+
string target = "is";
19+
char[] anyOf = target.ToCharArray();
1520

16-
start = str.Length/2;
17-
Console.WriteLine();
18-
Console.WriteLine("The first character occurrence from position {0} to {1}.",
19-
start, str.Length-1);
20-
Console.WriteLine("{1}{0}{2}{0}{3}{0}", Environment.NewLine, br1, br2, str);
21-
Console.Write("A character in '{0}' occurs at position: ", target);
21+
start = str.Length / 2;
22+
Console.WriteLine();
23+
Console.WriteLine("The first character occurrence " +
24+
$"from position {start} to {str.Length - 1}:");
25+
Console.WriteLine($"{Environment.NewLine}{br1}{Environment.NewLine}" +
26+
$"{br2}{Environment.NewLine}{str}{Environment.NewLine}");
27+
Console.Write($"A character in '{target}' occurs at position: ");
2228

23-
at = str.IndexOfAny(anyOf, start);
24-
if (at > -1)
25-
Console.Write(at);
26-
else
27-
Console.Write("(not found)");
28-
Console.WriteLine();
29-
}
30-
}
31-
/*
29+
at = str.IndexOfAny(anyOf, start);
30+
if (at > -1)
31+
Console.Write(at);
32+
else
33+
Console.Write("(not found)");
34+
Console.WriteLine();
35+
36+
/*
3237
33-
The first character occurrence from position 33 to 66.
34-
0----+----1----+----2----+----3----+----4----+----5----+----6----+-
35-
0123456789012345678901234567890123456789012345678901234567890123456
36-
Now is the time for all good men to come to the aid of their party.
38+
The first character occurrence from position 33 to 66.
39+
0----+----1----+----2----+----3----+----4----+----5----+----6----+-
40+
0123456789012345678901234567890123456789012345678901234567890123456
41+
Now is the time for all good men to come to the aid of their party.
3742
38-
A character in 'is' occurs at position: 49
43+
A character in 'is' occurs at position: 49
3944
40-
*/
41-
//</snippet1>
45+
*/
46+
//</snippet1>
47+
}
48+
}
Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,47 @@
1-
//<snippet1>
1+

22
// Sample for String.IndexOfAny(Char[], Int32, Int32)
33
using System;
44

5-
class Sample {
6-
public static void Main()
5+
class Example3
6+
{
7+
public static void Run()
78
{
8-
string br1 = "0----+----1----+----2----+----3----+----4----+----5----+----6----+-";
9-
string br2 = "0123456789012345678901234567890123456789012345678901234567890123456";
10-
string str = "Now is the time for all good men to come to the aid of their party.";
11-
int start;
12-
int at;
13-
int count;
14-
string target = "aid";
15-
char[] anyOf = target.ToCharArray();
9+
//<snippet1>
10+
string br1 = "0----+----1----+----2----+----3----" +
11+
"+----4----+----5----+----6----+-";
12+
string br2 = "012345678901234567890123456789" +
13+
"0123456789012345678901234567890123456";
14+
string str = "Now is the time for all good men " +
15+
"to come to the aid of their party.";
16+
string target = "aid";
17+
char[] anyOf = target.ToCharArray();
1618

17-
start = (str.Length-1)/3;
18-
count = (str.Length-1)/4;
19-
Console.WriteLine();
20-
Console.WriteLine("The first character occurrence from position {0} for {1} characters.", start, count);
21-
Console.WriteLine("{1}{0}{2}{0}{3}{0}", Environment.NewLine, br1, br2, str);
22-
Console.Write("A character in '{0}' occurs at position: ", target);
19+
int start = (str.Length - 1) / 3;
20+
int count = (str.Length - 1) / 4;
21+
Console.WriteLine();
22+
Console.WriteLine("The first character occurrence from " +
23+
$"position {start} for {count} characters:");
24+
Console.WriteLine($"{Environment.NewLine}{br1}{Environment.NewLine}{br2}" +
25+
$"{Environment.NewLine}{str}{Environment.NewLine}");
26+
Console.Write($"A character in '{target}' occurs at position: ");
2327

24-
at = str.IndexOfAny(anyOf, start, count);
25-
if (at > -1)
26-
Console.Write(at);
27-
else
28-
Console.Write("(not found)");
29-
Console.WriteLine();
30-
}
31-
}
32-
/*
28+
int at = str.IndexOfAny(anyOf, start, count);
29+
if (at > -1)
30+
Console.Write(at);
31+
else
32+
Console.Write("(not found)");
33+
Console.WriteLine();
34+
35+
/*
3336
34-
The first character occurrence from position 22 for 16 characters.
35-
0----+----1----+----2----+----3----+----4----+----5----+----6----+-
36-
0123456789012345678901234567890123456789012345678901234567890123456
37-
Now is the time for all good men to come to the aid of their party.
37+
The first character occurrence from position 22 for 16 characters.
38+
0----+----1----+----2----+----3----+----4----+----5----+----6----+-
39+
0123456789012345678901234567890123456789012345678901234567890123456
40+
Now is the time for all good men to come to the aid of their party.
3841
39-
A character in 'aid' occurs at position: 27
42+
A character in 'aid' occurs at position: 27
4043
41-
*/
42-
//</snippet1>
44+
*/
45+
//</snippet1>
46+
}
47+
}

snippets/fsharp/System/String/IndexOfAny/IndexOfAny1.fs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ module IndexOfAny1.fs
33
let chars = [| 'a'; 'e'; 'i'; 'o'; 'u'; 'y'
44
'A'; 'E'; 'I'; 'O'; 'U'; 'Y' |]
55
let s = "The long and winding road..."
6-
printfn $"The first vowel in \n {s}\nis found at position {s.IndexOfAny chars + 1}"
6+
printfn $"The first vowel in \n {s}\nis found at index {s.IndexOfAny chars}"
7+
78
// The example displays the following output:
89
// The first vowel in
910
// The long and winding road...
10-
// is found at position 3
11+
// is found at index 2
1112
// </Snippet1>

snippets/visualbasic/System/String/IndexOfAny/IndexOfAny1.vb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22
Option Strict On
33

44
' <Snippet1>
5-
Module Example
6-
Public Sub Main()
7-
Dim chars() As Char = { "a"c, "e"c, "i"c, "o"c, "u"c, "y"c,
5+
Module Example1
6+
Public Sub Run()
7+
Dim chars() As Char = { "a"c, "e"c, "i"c, "o"c, "u"c, "y"c,
88
"A"c, "E"c, "I"c, "O"c, "U"c, "Y"c }
99
Dim s As String = "The long and winding road..."
10-
Console.WriteLine("The first vowel in {2} {0}{2}is found at position {1}",
11-
s, s.IndexOfAny(chars) + 1, vbCrLf)
10+
Console.WriteLine("The first vowel in {2} {0}{2}is found at index {1}",
11+
s, s.IndexOfAny(chars), vbCrLf)
1212
End Sub
1313
End Module
14+
1415
' The example displays the following output:
1516
' The first vowel in
1617
' The long and winding road...
17-
' is found at position 3
18+
' is found at index 2
1819
' </Snippet1>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Library</OutputType>
5+
<TargetFramework>net9.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
</Project>

snippets/visualbasic/System/String/IndexOfAny/ixany2.vb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
'<snippet1>
22
' Sample for String.IndexOfAny(Char[], Int32)
3-
Class Sample
4-
Public Shared Sub Main()
3+
Class Example2
4+
Public Shared Sub Run()
55
Dim br1 As String = "0----+----1----+----2----+----3----+----4----+----5----+----6----+-"
66
Dim br2 As String = "0123456789012345678901234567890123456789012345678901234567890123456"
77
Dim str As String = "Now is the time for all good men to come to the aid of their party."
88
Dim start As Integer
99
Dim at As Integer
1010
Dim target As String = "is"
1111
Dim anyOf As Char() = target.ToCharArray()
12-
12+
1313
start = str.Length / 2
1414
Console.WriteLine()
1515
Console.WriteLine("Search for a character occurrence from position {0} to {1}.", _
@@ -34,4 +34,4 @@ End Class
3434
'
3535
'A character in 'is' occurs at position: 49
3636
'
37-
'</snippet1>
37+
'</snippet1>

snippets/visualbasic/System/String/IndexOfAny/ixany3.vb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'<snippet1>
22
' Sample for String.IndexOfAny(Char[], Int32, Int32)
3-
Class Sample
4-
Public Shared Sub Main()
3+
Class Example3
4+
Public Shared Sub Run()
55
Dim br1 As String = "0----+----1----+----2----+----3----+----4----+----5----+----6----+-"
66
Dim br2 As String = "0123456789012345678901234567890123456789012345678901234567890123456"
77
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
1010
Dim count As Integer
1111
Dim target As String = "aid"
1212
Dim anyOf As Char() = target.ToCharArray()
13-
13+
1414
start =(str.Length - 1) / 3
1515
count =(str.Length - 1) / 4
1616
Console.WriteLine()
1717
Console.WriteLine("The first character occurrence from position {0} for {1} characters.", start, count)
1818
Console.WriteLine("{1}{0}{2}{0}{3}{0}", Environment.NewLine, br1, br2, str)
1919
Console.Write("A character in '{0}' occurs at position: ", target)
20-
20+
2121
at = str.IndexOfAny(anyOf, start, count)
2222
If at > - 1 Then
2323
Console.Write(at)
@@ -35,4 +35,4 @@ End Class
3535
'
3636
'A character in 'aid' occurs at position: 27
3737
'
38-
'</snippet1>
38+
'</snippet1>

0 commit comments

Comments
 (0)