zoukankan      html  css  js  c++  java
  • 求字符串中最大数字

     public String GetMaxLenNumber(String inputStr)
           {
               //将字符串中的字符存放到数组中,便于处理
               char[] strArray = inputStr.toCharArray();
               //开始处理的位置
               int startPos = 0;
               //当前处理的字符长度
               int tempCount = 0;
               //数字的最长长度
               int maxLen = 0;
               //数组的总长度
               int len = strArray.length;
               int pos = 0;
               while (startPos < len)
               {
                   //循环中的临时最大长度
                   int tempMax = 0;
                   while (tempCount + startPos < len)
                   {
                       //开始处理的字符
                       char c = strArray[tempCount + startPos];
                       if ((c>='0')&&(c<='9'))
                       {
                           //如果是数字
                           tempMax++;
                           if (tempMax > maxLen)
                           {
                               maxLen = tempMax;
                               pos = startPos;
                           }                       
                       }
                       else
                       {
                           //不是数字
                           tempMax = 0;
                           startPos++;
                           break;
                       }
                       tempCount++;
                   }
                   if (startPos + tempCount == len)
                   {
                       break;
                   }
                   tempCount = 0;             
               }
               String s = inputStr.substring(pos,pos+maxLen);
               return s;
           } 

     判断char是否是数字

    Character.isDigit('9')
  • 相关阅读:
    0325JavaScript
    0322css样式表,选择器
    0320表单
    0313函数
    0312数组
    0311类
    0309笔记整理
    进制转换
    Xcode快捷键大全
    Android LearningNotes
  • 原文地址:https://www.cnblogs.com/fudapeng/p/3925243.html
Copyright © 2011-2022 走看看