java 代码
- /**
- * 文字列が半角カナを含んでいたら真を返します。
- */
- public static boolean includesHankana(String a) {
- byte[] b;
- try {
- b = a.getBytes("EUC_JP");
- } catch (UnsupportedEncodingException ex) {
- return false;
- }
- for (int i = 0; i < b.length; i++) {
- if (b[i] == -114)
- return true;
- }
- return false;
- }
- /**
- * 文字列が全角文字を含んでいたら真を返します。
- */
- public static boolean includesMultibytes(String a) {
- byte[] b;
- try {
- b = a.getBytes("EUC_JP");
- } catch (UnsupportedEncodingException ex) {
- return false;
- }
- for (int i = 0; i < b.length; i++) {
- if (b[i] == -114)
- i++;
- else if (b[i] < 0)
- return true;
- // 0x8e以外の0x80ビットが立っている文字があったら当たり
- }
- return false;
- }