0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

JAVA テストコード 制御文字を入力して検証するための準備

Posted at

制御文字を入力してその内容を検証したい→制御文字を入れる方法がわからない。。。
現場で詰まったのでメモ

制御文字は直接キーボード入力することが難しいため
16進法コードから逆変換することにした

今回は制御文字の「ユニット区切り」を使用
16進法のコードは「1F」
これを下記実装の通りに記載してあげれば、完了

Test
//省略
String hexString = "1F";
byte[] bytes = Hex.decodeHex(hexString.toCharArray());
String newStr = new String(byte, "US-ASCII");
//省略

制御文字のバリエーション実装については
調べれば色々出てくると思うのでここでは省略
※下記実装は正規表現


preg_replace('/[\x00-\x09\x0B\x0C\x0E-\x1F\x7F]/', '', $XXX)
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?