/** * 判断字符串中某个字符存在的个数 * @param str1 完整字符串 * @param str2 要统计匹配个数的字符 * @return */ public static int countStr(String str1, String str2) { int count=0; if (str1.indexOf(str2) == -1) { return 0; } while(str1.indexOf(str2)!=-1){ count++; str1=str1.substrin…
  java判断字符串中是否包含中文并过滤掉中文 CreateTime--2017年9月6日08:48:59 Author:Marydon 1.判断字符串中是否包含中文方法封装 /** * 判断字符串中是否包含中文 * @param str * 待校验字符串 * @return 是否为中文 * @warn 不能校验是否为中文标点符号 */ public static boolean isContainChinese(String str) { Pattern p = Pattern.compil…
package com.test; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Test { @org.junit.Test public void test(){ String fileName = "test,中文"; System.out.println(filterChinese(fileName)); } /** * 判断字符串中是否包含中文 * @param str…
/** * 判断字符串中是否含有中文 */ public static boolean isCNChar(String s){ boolean booleanValue = false; for(int i=0; i<s.length(); i++){ char c = s.charAt(i); if(c > 128){ booleanValue = true; break; } } return booleanValue; } 如果true,包含中文: 如果false,不包含中文…
原文:http://www.open-open.com/code/view/1426332240717 判断字符串中是否含有汉字: String str = "test中文汉字"; String regEx = "[//u4e00-//u9fa5]"; /** * 判断有没有中文 */ if (str.getBytes().length == str.length()) { System.out.println("无汉字"); } else {…
实现代码: /* * 判断字符串中是否含有英文,包含返回true */ public boolean isENChar(String string) { boolean flag = false; Pattern p = Pattern.compile("[a-zA-z]"); if(p.matcher(string).find()) { flag = true; } return flag; }…
Java判断一个字符串str中中文的个数,经过总结,有以下几种方法(全部经过验证),可根据其原理判断在何种情况下使用哪个方法: 1. char[] c = str.toCharArray(); for(int i = 0; i < c.length; i ++) { String len = Integer.toBinaryString(c[i]); if(len.length() > 8) count ++; } 根据一个中文占两个字节,假如一个字符的字节数大于8,则判断为中文. 2 . S…
通过2个函数CHARINDEX和PATINDEX以及通配符的灵活使用 函数:CHARINDEX和PATINDEX CHARINDEX:查某字符(串)是否包含在其他字符串中,返回字符串中指定表达式的起始位置. PATINDEX:查某字符(串)是否包含在其他字符串中,返回指定表达式中某模式第一次出现的起始位置:如果在全部有效的文本和字符数据类型中没有找到该模式,则返回零.特殊:可以使用通配符! 例子: 查询字符串中是否包含非数字字符 SELECT PATINDEX('%[^0-9]%', '1235…
package com.cmc.util; import java.util.regex.Pattern; public class CharUtil { public static void main(String[] args) { String[] strArr = new String[] { "www.micmiu.com", "!@#$%^&*()_+{}[]|\"'?/:;<>,.", "!¥……()——::“”…
public static int countStr(String str1, String str2) { int counter=0; if (str1.indexOf(str2) == -1) { return 0; } while(str1.indexOf(str2)!=-1){ counter++; str1=str1.substring(str1.indexOf(str2)+str2.length()); } return counter; }…