1- //<snippet1>
1+
22// Sample for String.IndexOfAny(Char[], Int32, Int32)
33using 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+ }
0 commit comments