1
1

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 5 years have passed since last update.

文字コード違うファイル間で2バイト文字条件分岐

Last updated at Posted at 2016-08-18

ホントは使いたくないけど使わざるを得なかったVBS備忘録。
この無駄な苦労を繰り返さないために。

#####2つライブラリ導入&初期設定
BASP21は適当に放り込んでおく

Set oUtf8BinaryConverter = CreateObject("basp21")
Set oUtf8ShiftjisConverter = CreateObject("Microsoft.XMLDOM").createElement("tmp")  
oUtf8ShiftjisConverter.DataType = "bin.hex"   

#####2バイト文字は文字コードを16進数で直打ちしてバイナリ化
文字コードを自動算出する気力は無かった

oUtf8ShiftjisConverter.Text = "819b"	'これは"○"
bitAppropriate1 = oUtf8ShiftjisConverter.NodeTypedValue  

#####1バイト文字ならMicrosoft.XMLDOMライブラリでバイナリ化

bitAppropriate2 = oUtf8BinaryConverter.ByteArray(strTwoBiteText,0) 

#####MidB関数で再度文字列化して比較
中身はカオスな文字化け状態

IF MidB(bitAppropriate1,1) = MidB(bitAppropriate2,1) THEN
  ...
END IF
1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?