Q:
How to convert the string "1. b2.c3. a4.b5. a6.c7. ac8.bc9. ac10.bd11. (1) 810 N (2) 5 m/s 12.5 times":
1. B
2. c
3.
4. B
5.
6. C
7. AC
8. BC
9. AC
10. BD
11. (1) 810 N (2) 5 m/s 12.5 times
The punctuation marks of the numbers are English characters, and other punctuation marks are Chinese characters.
Refer: http://bbs.csdn.net/topics/390534946
A:
Use Traditional Character Parsing to solve the problem. Of course, using regular expressions will be simpler.
Class program {static void main (string [] ARGs) {// The text to be parsed string TXT = "1. b2.c3. a4.b5. a6.c7. ac8.bc9. ac10.bd11. (1) 810 N (2) 5 m/s 12.5 times "; // defines a stack to store the sub-String Stack <string> words = new stack <string> (); // define the cursor int start = TXT. length-1; int end = start; // parse text forward from the end of the string to reduce the number of cursor moves while (Start> 0) {If (txt [start] = '. ') {While (start --> 0) {If (txt [start] <'0' | TXT [start]> '9') break;} words. push (txt. substring (start + 1, end-Start); End = start;} start --;} // output result while (words. count> 0) {console. writeline (words. pop ());}}}
Output: