欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

C#教程

當(dāng)前位置:主頁 > 軟件編程 > C#教程 >

C#算法函數(shù):獲取一個字符串中的最大長度的數(shù)字

來源:本站原創(chuàng)|時間:2020-01-10|欄目:C#教程|點擊: 次

/// <summary>
/// 獲取字符串最長的數(shù)字
/// </summary>
/// <param name="inputStr">輸入字符串</param>
/// <returns>最長數(shù)字</returns>
public string GetMaxLenNumber(string inputStr)
{
  //將字符串中的字符存放到數(shù)組中,便于處理
  char[] strCharArray = inputStr.ToCharArray();
  //開始處理的位置
  int startPos = 0;
  //當(dāng)前處理的字符長度
  int tempCharCount = 0;
  //數(shù)字的最長長度
  int maxLen = 0;
  //數(shù)組的總長度
  int len = strCharArray.Length;
  int pos = 0;
  while (startPos < len)
  {
    //循環(huán)中的臨時最大長度
    int tempMax = 0;
    while (tempCharCount + startPos < len)
    {
      //開始處理的字符
      char c = strCharArray[tempCharCount + startPos];
      if (char.IsNumber(c))
      {
        //如果是數(shù)字
        tempMax++;
        if (tempMax > maxLen)
        {
          maxLen = tempMax;
          pos = startPos;
        }            
      }
      else
      {
        //不是數(shù)字
        tempMax = 0;
        startPos++;
        break;
      }
      tempCharCount++;
    }
    if (startPos + tempCharCount == len)
    {
      break;
    }
    tempCharCount = 0;       
  }
  string s = inputStr.Substring(pos, maxLen);
  return s;
}

以上就是本文的全部內(nèi)容,希望能給大家一個參考,也希望大家多多支持我們。

上一篇:asp.net獲取系統(tǒng)當(dāng)前時間的方法詳解

欄    目:C#教程

下一篇:C#初始化數(shù)組的方法小結(jié)

本文標(biāo)題:C#算法函數(shù):獲取一個字符串中的最大長度的數(shù)字

本文地址:http://mengdiqiu.com.cn/a1/C_jiaocheng/6406.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時內(nèi)進行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有