1. Method Function Description
There is A string: A-B-C-D-E-F-G-H-I-J, the substring is: A-D, G-H,
Function: Find the string D-G and H-J.
2. Code Description and description
(1) thoughts
Loop string, which compares to the first character of the substring one by one,
If the sub-string list does not exist, add the Sub-string and set the first character of the sub-string to this string;
If this character exists in the substring, the last character of the substring is obtained and the segment is skipped cyclically.
(2) C # code
1 private List <string> FillMidList (List <string> stringList, List <string> midList)
2 {
3 List <string> rtn = new List <string> ();
4 List <string> strList = null; // Char List
5 string start = string. Empty; // Start Char
6 string end = string. Empty; // End Char
7 bool isFind = false;
8 bool isFindEnd = false; // Find End Char
9
10 for (int I = 0; I <stringList. Count; I ++)
11 {
12 start = stringList [I];
13 // If exit char
14 foreach (var item in midList)
15 {
16 if (start = item [0])
17 {
18 if (isFindEnd = true)
19 {
20 end = start;
21}
22 isFind = true;
23 start = item [item. Count-1];
24 break;
25}
26}
27
28 if (isFind = true)
29 {
30 isFind = false;
31 // Adjust index
32 for (int j = 0; j <stringList. Count; j ++)
33 {
34 if (stringList [j] = start)
35 {
36 I = j-1;
37 break;
38}
39}
40 if (isFindEnd = true)
41 {
42 strList. Add (end );
43 rtn. Add (strList );
44 isFindEnd = false;
45 end = string. Empty;
46}
47}
48 else
49 {
50 if (isFindEnd = true)
51 {
52 // Add the last
53 if (start = stringList [stringList. Count-1])
54 {
55 strList. Add (start );
56 rtn. Add (strList );
57}
58}
59 else
60 {
61 strList = new List <string> ();
62 strList. Add (start );
63 isFindEnd = true;
64}
65}
66}
67
68 return rtn;
69}
3. Description
This feature is sometimes encountered in the project process. I personally feel that it is a little complicated to write and provide a comment for your discussion.