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
查看全文
相关阅读:
netty 学习总结
tps 真正理解
Eureka 学习
h5前端编译项目问题
web自动化学习
python unittest自动化执行的几种方式
python pip install XX 出现Could not fetch URL https://pypi.python.org/simple/pool/: There was a problem confirming
TypeError: 'module' object is not callable
简明HTML+CSS实现圣杯布局方法及要点(浮动实现)
负Margin技术,轻松实现 1.自适应两列布局,2.元素垂直居中(相对定位)
原文地址:https://www.cnblogs.com/yiki/p/884643.html
最新文章
为何在 Modal 中调用 form 控制台会报错?
prefetch 性能优化
jmeter 插件
python之demjson&&json 比较
C# Event
Java设计模式-工厂方法模式
Java设计模式-单例模式
Java设计模式-简单工厂模式
Linux下设置Redis开机自启脚本
Linux下安装Redis
热门文章
Linux下安装MySQL
Linux开放防火墙指定端口
Linux下安装Tomcat
Linux下安装JDK1.8
VMware14 下载安装CentOS7
拦截器和过滤器的对比,很实在
spring 事务总结
springcloud sleth+zipkin 使用原理
springcloud Feign实现原理
springcloud ribbon实现原理
Copyright © 2011-2022 走看看