File tree 1 file changed +35
-0
lines changed
1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change
1
+ string [ ] myStrings = new string [ 2 ] { "I like pizza. I like roast chicken. I like salad" , "I like all three of the menu choices" } ;
2
+ int stringsCount = myStrings . Length ;
3
+
4
+ string myString = "" ;
5
+ int periodLocation = 0 ;
6
+
7
+ for ( int i = 0 ; i < stringsCount ; i ++ )
8
+ {
9
+ myString = myStrings [ i ] ;
10
+ periodLocation = myString . IndexOf ( "." ) ;
11
+
12
+ string mySentence ;
13
+
14
+ // extract sentences from each string and display them one at a time
15
+ while ( periodLocation != - 1 )
16
+ {
17
+
18
+ // first sentence is the string value to the left of the period location
19
+ mySentence = myString . Remove ( periodLocation ) ;
20
+
21
+ // the remainder of myString is the string value to the right of the location
22
+ myString = myString . Substring ( periodLocation + 1 ) ;
23
+
24
+ // remove any leading white-space from myString
25
+ myString = myString . TrimStart ( ) ;
26
+
27
+ // update the comma location and increment the counter
28
+ periodLocation = myString . IndexOf ( "." ) ;
29
+
30
+ Console . WriteLine ( mySentence ) ;
31
+ }
32
+
33
+ mySentence = myString . Trim ( ) ;
34
+ Console . WriteLine ( mySentence ) ;
35
+ }
You can’t perform that action at this time.
0 commit comments