Fetch two character string as intermediate




        class MidString {

            // exception occurs! 
            /// <Summary> 
            /// search string 
            /// </ Summary> 
            /// <param name = "Source"> the target string </ param> 
            /// <param name = "Start"> before the character string </ param> 
            string </ param> after /// <param name = "End"> 
            /// <Returns> obtaining an intermediate two strings of string </ Returns> 
            public  static  string the Find ( string Source, string Start, string End) {     // Get the search to the number of   
                the try {
                     int I, J;
                     // startIndex is less than 0 (zero) or greater than this length of the string 
                    // public int the IndexOf (string value, int startIndex); 
                    I = source.IndexOf (start, 0) +    start.
                    source.IndexOf = J (End, I);         // end position     
                    return source.Substring (I, J - I);        the number of search // taken, with the end position - the start position, and returns    
                }
                catch {
                    return " ";
                }
            }

            public  static  String Find_3 ( String Source, String Start, String End) {
                 int X = source.IndexOf (Start);
                 IF (X <0) // not found return empty 
                    return "";
                 Int Y = source.IndexOf (End, X + start.Length); // go from the first string is found after 
                IF (Y <0) // not found return empty 
                    return "";
                return source.Substring(x + start.Length, y - x - start.Length);
            }

            public static string Find_4(string sourse, string start, string end) {
                string result = string.Empty;
                int x, y;
                try {
                    x = sourse.IndexOf(start);
                    if (x == -1)
                        return result;
                    string z = sourse.Substring(x + start.Length);
                    y = z.IndexOf(end);
                    if (y == -1)
                        return result;
                    result = z.Remove(y);
                }
                catch (Exception ex) {
                    MessageBox.Show(ex.Message);
                }
                return result;
            }

            public static string RegexFind(string sourse, string start, string end) {
                Regex rg = new Regex("(?<=(" + start + "))[.\\s\\S]*?(?=(" + end + "))", RegexOptions.Multiline | RegexOptions.Singleline);
                return rg.Match(sourse).Value;
            }

            /// <summary>
            /// 转换成一行
            /// </summary>
            /// <param name="sText"></param>
            /// <returns></returns>
            public static string ReplaceWhiteString(string sText) {
                sText = sText.Replace("\r", "");
                sText = sText.Replace("\n", "");
                sText = sText.Replace("\t", "");
                sText = sText.Replace(" ", "");
                return sText;
            }
        }

Guess you like

Origin www.cnblogs.com/xe2011/p/12116390.html