zoukankan
html css js c++ java
算法函数:得到一个字符串中的最大长度的数字
/**/
///
<summary>
///
获取字符串最长的数字
///
</summary>
///
<param name="inputStr">
输入字符串
</param>
///
<returns>
最长数字
</returns>
public
string
GetMaxLenNumber(
string
inputStr)
{
//
将字符串中的字符存放到数组中,便于处理
char
[] strCharArray
=
inputStr.ToCharArray();
//
开始处理的位置
int
startPos
=
0
;
//
当前处理的字符长度
int
tempCharCount
=
0
;
//
数字的最长长度
int
maxLen
=
0
;
//
数组的总长度
int
len
=
strCharArray.Length;
int
pos
=
0
;
while
(startPos
<
len)
{
//
循环中的临时最大长度
int
tempMax
=
0
;
while
(tempCharCount
+
startPos
<
len)
{
//
开始处理的字符
char
c
=
strCharArray[tempCharCount
+
startPos];
if
(
char
.IsNumber(c))
{
//
如果是数字
tempMax
++
;
if
(tempMax
>
maxLen)
{
maxLen
=
tempMax;
pos
=
startPos;
}
}
else
{
//
不是数字
tempMax
=
0
;
startPos
++
;
break
;
}
tempCharCount
++
;
}
if
(startPos
+
tempCharCount
==
len)
{
break
;
}
tempCharCount
=
0
;
}
string
s
=
inputStr.Substring(pos, maxLen);
return
s;
}
作者:
jillzhang
出处:
http://jillzhang.cnblogs.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
查看全文
相关阅读:
定位--position属性
浮动
超链接伪类
对齐方式
字体样式
标准文档流
CSS
表单
框架
内部类
原文地址:https://www.cnblogs.com/jillzhang/p/881148.html
最新文章
css
超链接伪类
HTML基础
Java语言编程注意事项
了解Java
常用类——包装类
类和对象
类图
常见类——Object
日志
热门文章
控件
RadioButton(单选按钮)
EditText(输入框)
TextView控件
Activity
StringBuffer
String
导包
包的命名规范
带参数方法
Copyright © 2011-2022 走看看