The previous phase encountered a string truncation problem. Because the string is long, it may take tens of thousands of characters (in XML format) to extract content between the two nodes in the middle, it takes a lot of effort to find the regular expressions that can be used on the Internet. When I use my work, it is the most painful to encounter such a problem. Although there are many resources on the Internet, it is time-consuming, time-consuming, and annoying to screen. Now you are idle. I will summarize the. NET Method for intercepting strings. For the sake of intuition, I will use the console to demonstrate each method. If not, please add it. If not, please forgive me. ① String. substring this method is known to everyone, but for the sake of being intuitive, I wrote a super simple code to run it: string str = "abcdefghijk"; string subStr = str. substring (0, 5); Console. write (subStr); Console. readKey (); the first parameter is the index to be intercepted (remember to start with 0), and the second parameter is the string length to be intercepted. For example, the last three characters are intercepted: string str = "abcdefghijk"; string subStr = str. substring (str. length-3, 3); Console. write (subStr); Console. readKey (); actually, it is a change of thinking. Substring is often used in combination with the indexof function. It is best to practice it to help you search for relevant information. ② String. the Split function can be used to intercept strings with special characters. For example, a time format is like this:. I want to take the year, month, and day out separately. You can use the regular method, you can also use the Split function: string str = "2014-2-8"; string [] stArray = str. split (new char [1] {'-'}); string subStrYear = stArray [0]; string subStrMonth = stArray [1]; string subStrDay = stArray [2]; Console. write (subStrYear); Console. write ("\ n"); Console. write (subStrMonth); Console. write ("\ n"); Console. write (subStrDay); Consol E. readKey (); if multiple special characters exist, such as aa-bb-cc | dd | ee | ff, replace the Split parameter with new char [2] {'-', '|. The Split function can also be used with the regular expression to intercept the string: string str = "Wei --- de -- You ------ really-great"; string [] strArray = System. text. regularExpressions. regex. split (str1, @ "\-+"); foreach (string I in strArray) Console. write (I. toString (); Console. readKey (); ③ Regular Expression: first, the regular expression must reference the namespace: System. text. regularExpressions; regular expressions are widely used. If you want to intercept a string or something, you can search the strings on the Internet. However, if you can use them, you have to do it yourself, if you have tried to use it, you can actually use it. Below is a demo of some useful regular expressions: 1 ."(? <= ('Start position of truncation ') [. \ s \ S] *? (? = ('Capture end location') "string str =" aabbccdd <Msg> This is I want </Msg> eeffgghh "; string subStart =" <Msg> "; string subEnd = "</Msg>"; Regex MsgRegex = new Regex ("(? <= ("+ SubStart +") [. \ s \ S] *? (? = ("+ SubEnd +") ", RegexOptions. multiline | RegexOptions. singleline); Match MsgMc = MsgRegex. match (str); string subString = MsgMc. groups [0]. value; Console. write (subString); Console. readKey (); 2. "(? I )(? <= Truncation start position) [^ \ "] * (? = Truncation end position) "string str =" aabbccdd <Msg> This is I want again </Msg> eeffgghh "; Match MsgMc = Regex. Match (str ,"(? I )(? <= <Msg>) [^ \ "] * (? = </Msg>) "); string subString = MsgMc. groups [0]. value; Console. write (subString); Console. readKey (); let's look at these two examples. I won't write them, and it's hard to find them. I don't know how to write it. I met a regular expression in CSDN and recommended it to everyone. You can study in his space: