C # algorithm function: Gets a digital _c# tutorial of the maximum length in a string

Source: Internet
Author: User
<summary>///get the longest string of digits///</summary>///<param name= "inputstr" > Input string </param>///<ret urns> Maximum number </returns> public string Getmaxlennumber (string inputstr) {//storing characters in a string in an array for easy processing char[] Strchararra
  y = Inputstr.tochararray ();
  position to begin processing int startpos = 0;
  The character length of the current processing int tempcharcount = 0;
  The longest length of the number int maxlen = 0;
  Total length of array int len = strchararray.length;
  int pos = 0;
    while (Startpos < len) {//the temporary maximum length int tempmax = 0 in the loop;
      while (Tempcharcount + startpos < len) {//start processing char c = strchararray[tempcharcount + startpos]; if (char.
        Isnumber (c)) {//If it is a digital tempmax++;
          if (Tempmax > MaxLen) {maxlen = Tempmax;
        pos = startpos;
        } else {//not number Tempmax = 0;
        startpos++;
      Break
    } tempcharcount++;
    } if (startpos + tempcharcount = len) {  Break       
  } tempcharcount = 0;
  string s = inputstr.substring (pos, maxlen);
return s; }

The above is the entire content of this article, I hope to give you a reference, but also hope that we support the cloud-dwelling community.

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.