「Java入門」半角カタカナを判定するコード

Javaコード:
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class HanKakuTest {
public static boolean isHanKakuFunc(String source) {
Pattern pattern = Pattern.compile(“^[\\uFF65-\\uFF9F\\s-]+$");
Matcher matcher = pattern.matcher(source);
return matcher.matches();
}

public static void main(String[] args) {

String str1 = “トウキョウーーシナガワ";
String str2 = " トウキョウ–シナガワ “;
System.out.println(“実行結果:\n");
System.out.println(isHanKakuFunc(str1));
System.out.println(isHanKakuFunc(str2));

}

}
実行結果:

true
false

Java

Posted by arkgame