0
0

【Java】JIS X 0213 文字チェック

Last updated at Posted at 2024-01-04

仕事で、文字列に JIS X 0213以外が含まれないことをチェックする処理を実装しろと言われたのですが、調べてもなかなか出てこなかったので、備忘録として記載しておきます。

コード

処理自体は簡単で、charsetNamex-SJIS_0213を指定して、byte[]String に変換して、変換前後の値が一致することを確認します。

String target = "小⃝𠮷";
byte[] targetBytes = target.getBytes("x-SJIS_0213");

String after = new String(targetBytes, "x-SJIS_0213");
System.out.println("check:" + after.equals(target));

String target に含まれる値が JIS X 0213の文字のみであれば、after.equals(target)true
JIS X 0213以外の文字が含まれる場合は、false となります。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0