zoukankan
html css js c++ java
C# 判断string 是否可为数字
//
正则表达式
//
a)
using
System;
using
System.Text.RegularExpressions;
public
bool
IsNumber(String strNumber)
{
Regex objNotNumberPattern
=
new
Regex(
"
[^0-9.-]
"
);
Regex objTwoDotPattern
=
new
Regex(
"
[0-9]*[.][0-9]*[.][0-9]*
"
);
Regex objTwoMinusPattern
=
new
Regex(
"
[0-9]*[-][0-9]*[-][0-9]*
"
);
String strValidRealPattern
=
"
^([-]|[.]|[-.]|[0-9])[0-9]*[.]*[0-9]+$
"
;
String strValidIntegerPattern
=
"
^([-]|[0-9])[0-9]*$
"
;
Regex objNumberPattern
=
new
Regex(
"
(
"
+
strValidRealPattern
+
"
)|(
"
+
strValidIntegerPattern
+
"
)
"
);
return
!
objNotNumberPattern.IsMatch(strNumber)
&&
!
objTwoDotPattern.IsMatch(strNumber)
&&
!
objTwoMinusPattern.IsMatch(strNumber)
&&
objNumberPattern.IsMatch(strNumber);
}
//
b)
public
static
bool
IsNumeric(
string
value)
{
return
Regex.IsMatch(value,
@"
^[+-]?\d*[.]?\d*$
"
);
}
public
static
bool
IsInt(
string
value)
{
return
Regex.IsMatch(value,
@"
^[+-]?\d*$
"
);
}
public
static
bool
IsUnsign(
string
value)
{
return
Regex.IsMatch(value,
@"
^\d*[.]?\d*$
"
);
}
//
遍历
//
a)
public
bool
isnumeric(
string
str)
{
char
[] ch
=
new
char
[str.Length];
ch
=
str.ToCharArray();
for
(
int
i
=
0
;i
{
if
(ch[i]
<
48
||
ch[i]
>
57
)
return
false
;
}
return
true
;
}
//
b)
public
bool
IsInteger(
string
strIn)
{
bool
bolResult
=
true
;
if
(strIn
==
""
)
{
bolResult
=
false
;
}
else
{
foreach
(
char
Char
in
strIn)
{
if
(
char
.IsNumber(Char))
continue
;
else
{
bolResult
=
false
;
break
;
}
}
}
return
bolResult;
}
//
c)
public
static
bool
isNumeric(
string
inString)
{
inString
=
inString.Trim();
bool
haveNumber
=
false
;
bool
haveDot
=
false
;
for
(
int
i
=
0
;i
{
if
(Char.IsNumber(inString[i]))
{
haveNumber
=
true
;
}
else
if
(inString[i]
==
'
.
'
)
{
if
(haveDot)
{
return
false
;
}
else
{
haveDot
=
true
;
}
}
else
if
(i
==
0
)
{
if
(inString[i]
!=
'
+
'
&&
inString[i]
!=
'
-
'
)
{
return
false
;
}
}
else
{
return
false
;
}
if
(i
>
20
)
{
return
false
;
}
}
return
haveNumber;
}
}
from:http://miaoshunping.bokee.com/5836813.html
查看全文
相关阅读:
POJ1475 Pushing Boxes 华丽丽的双重BFS
POJ3322 Bloxorz I 无脑广搜(我死了。。。)
CH2401 送礼物 双向搜索
POJ2248 Addition Chains 迭代加深
POJ3074 Sudoku 剪枝深(神?)搜
Luogu P1120 小木棍 [数据加强版] 来来来我们一起来剪枝,剪枝,剪枝、、、
Luogu P4095 [HEOI2013]Eden 的新背包问题 思维/动规
Luogu P5201 [USACO19JAN]Shortcut 最短路树???
Luogu P5122 [USACO18DEC]Fine Dining 最短路
Luogu P1608 路径统计 最短路计数
原文地址:https://www.cnblogs.com/yiki/p/884643.html
最新文章
C++ STL map
ubuntu----ip修改
pytorch BatchNorm参数详解,计算过程
深度网络的参数量的计算
hadoop 2.7.3 (hadoop2.x)使用ant制作eclipse插件hadoop-eclipse-plugin-2.7.3.jar
hadoop推荐
hadoop2 Ubuntu 下安装部署
Hadoop 修改源码以及将修改后的源码应用到部署好的Hadoop中
Hadoop 三大调度器源码分析及编写自己的调度器
YARN(MapReduce 2)运行MapReduce的过程-源码分析
热门文章
安装Tomcat(windows系统和linux系统)
Servlet入门
编写hadoop程序并打成jar包上传到hadoop集群运行
Crossword Expert CodeForces
Intercity Travelling CodeForces
Tokitsukaze and Strange Rectangle CodeForces
Tokitsukaze and Duel CodeForces
Sonya and Bitwise OR CodeForces
POJ3635 Full Tank? 优先队列BFS or 分层图最短路 or DP?
Luogu P2243 电路维修 双端队列BFS
Copyright © 2011-2022 走看看