String segment Filling

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.