CSHARP: searching within a string

Source: Internet
Author: User
1    ///   <Summary>  2       ///  20130118  3       ///  Whether the search string exists  4       ///  Juwen youyou Computer Information Technology Co., Ltd.  5       ///  Jie Wei Studio  6       ///  </Summary>  7       Public   Class  Stringsearchclass  8   {  9           ///   <Summary>  10           ///  Search for strings  11           ///  Stringindexof "); 12           ///   </Summary>  13           ///   <Param name = "str1">  String  </Param>  14           ///   <Param name = "judgestr">Query  Character or string  </Param>  15           ///   <Returns> Whether the returned result exists  </Returns>  16           Public   Static   Bool Stringindexof ( String Str1, String  Searchstr)  17   {  18               Bool Isexist = True  ;  19 Str1 = "  ,  " + Str1 + "  ,  "  ;  20               String [] STRs = searchstr. Split ( New   Char [] { '  ,  '  }, Stringsplitoptions. removeemptyentries ); 21               Foreach ( String Strtemp In  STRs)  22   {  23                   If (Str1.indexof ( '  ,  ' + Strtemp + '  ,  ' ) =- 1 )  24   {  25 Isexist = False  ;  26                       Break  ;  27   }  28   }  29               Return  Isexist; 30   }  31           ///   <Summary>  32           ///  Search for strings  33           ///  Yan juwen  34           ///   </Summary>  35           ///   <Param name = "str1"> String  </Param>  36           ///   <Param name = "judgestr">Query  Character or string  </Param>  37           ///   <Returns> </returns>  38           Public   Static   Bool Stringcontains ( String Str1,String  Searchstr)  39   {  40               Bool Isexist = True  ;  41 Str1 = "  ,  " + Str1 + "  ,  "  ; 42               String [] STRs = searchstr. Split ( New   Char [] { '  ,  '  }, Stringsplitoptions. removeemptyentries );  43               Foreach ( String Strtemp In  STRs)  44   { 45                   If (! Str1.contains ( '  ,  ' + Strtemp + '  ,  '  ))  46   {  47 Isexist = False  ;  48                       Break ;  49   }  50   }  51               Return  Isexist;  52   }  53           ///   <Summary>  54           ///  Search for strings  55          ///  Yan juwen  56           ///   </Summary>  57           ///   <Param name = "str1">  String  </Param>  58           ///   <Param name = "judgestr">Query  Character or string  </Param>  59          ///   <Returns> </returns>  60           Public   Static   Bool Stringregex ( String Str1, String  Searchstr)  61   {  62               Bool Isexist = True  ;  63 Str1 = "  ,  " + Str1 + "  ,  "  ;  64               String [] STRs = searchstr. Split ( New   Char [] { '  ,  '  }, Stringsplitoptions. removeemptyentries ); 65               Foreach ( String Strtemp In  STRs)  66   {  67                   If (! RegEx. Match (str1, strtemp, regexoptions. ignorecase). Success)  68   {  69 Isexist = False  ; 70   }  71   }  72               Return  Isexist;  73   }  74 }

Zookeeper:

 1   //  Zookeeper  2 Stopwatch Sw = New  Stopwatch (); 3               4   Sw. Start ();  5              //  Bool S = stringindexof ");  //  True, time consumed: 00: 00: 00.0003557  6              //  Bool S = stringcontains ");  //  True, time consumed: 00: 00: 00.0003625  7               Bool S = stringregex ("  1, 2, 3, 4, 5, 6  " , "  1, 6  " ); //  False. Time consumed: 00: 00: 00.0286617  //  True, time consumed: 00: 00: 00.0008295  //  True, time consumed: 00: 00: 00.0008237  8   Sw. Stop ();  9              This . Textbox1.text = S. tostring () + "  , Time consumed:  " + Sw. elapsed. tostring ();

 

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.