String数字操作
来源:互联网 发布:湖南卫视杜海涛知乎 编辑:程序博客网 时间:2024/06/06 06:52
// 判断一个字符串是否都为数字
public boolean isDigit(String strNum) {
return strNum.matches("[0-9]{1,}");
}
// 判断一个字符串是否都为数字
public boolean isDigit(String strNum) {
Pattern pattern = Pattern.compile("[0-9]{1,}");
Matcher matcher = pattern.matcher((CharSequence) strNum);
return matcher.matches();
}
//截取数字
public String getNumbers(String content) {
Pattern pattern = Pattern.compile("\\d+");
Matcher matcher = pattern.matcher(content);
while (matcher.find()) {
return matcher.group(0);
}
return "";
}
// 截取非数字
public String splitNotNumber(String content) {
Pattern pattern = Pattern.compile("\\D+");
Matcher matcher = pattern.matcher(content);
while (matcher.find()) {
return matcher.group(0);
}
return "";
}
// 判断一个字符串是否含有数字
public boolean HasDigit(String content) {
boolean flag = false;
Pattern p = Pattern.compile(".*\\d+.*");
Matcher m = p.matcher(content);
if (m.matches()) {
flag = true;
}
return flag;
public boolean isDigit(String strNum) {
return strNum.matches("[0-9]{1,}");
}
// 判断一个字符串是否都为数字
public boolean isDigit(String strNum) {
Pattern pattern = Pattern.compile("[0-9]{1,}");
Matcher matcher = pattern.matcher((CharSequence) strNum);
return matcher.matches();
}
//截取数字
public String getNumbers(String content) {
Pattern pattern = Pattern.compile("\\d+");
Matcher matcher = pattern.matcher(content);
while (matcher.find()) {
return matcher.group(0);
}
return "";
}
// 截取非数字
public String splitNotNumber(String content) {
Pattern pattern = Pattern.compile("\\D+");
Matcher matcher = pattern.matcher(content);
while (matcher.find()) {
return matcher.group(0);
}
return "";
}
// 判断一个字符串是否含有数字
public boolean HasDigit(String content) {
boolean flag = false;
Pattern p = Pattern.compile(".*\\d+.*");
Matcher m = p.matcher(content);
if (m.matches()) {
flag = true;
}
return flag;
}
java中判断字符串是否为数字的三种方法 :
1.用JAVA自带的函数
public static boolean isNumeric(String str) {
for (int i = str.length(); --i >= 0;) {
if (!Character.isDigit(str.charAt(i))) {
return false;
}
}
return true;
}
2.用正则表达式
public static boolean isNumeric(String str) { Pattern pattern = Pattern.compile("[0-9]*"); return pattern.matcher(str).matches(); }
阅读全文
0 0
- String数字操作
- 数字操作
- 数字左补零(String,NumberFormat)
- string与数字转换
- 数字 string 转换
- freemarker String 转 数字
- string 操作
- string操作
- String 操作
- String操作
- string操作
- String操作
- String操作
- String操作
- String操作
- string操作
- String操作
- string操作
- CURL模拟post,get提交数据-实际应用
- 上传图片显示,ajaxUpload
- 删除数字-LintCode
- PHPStorm 配置自定义的Apache与PHP解释器
- Python中有关文件的操作
- String数字操作
- 子类实例化
- JQuery选择器小知识积累
- java XML的SAX解析方式
- Linux环境下配置简单DNS服务
- SpringMVC笔记(四)拦截器
- Selenium2+Python2.0自动化测试【10】 复选框
- CCF CSP 认证 201612-2 工资计算 java版
- Unity3D学习:结合Kinect进行游戏开发 | 孤舟博客