全角文字と半角文字を判別する方法を教えていただきたいです。
Show older comments
MATLABで全角文字と半角文字を判別する方法を教えていただきたいでしょうか。
例えば、["A" "B" "1" "2" "A" "B" "1" "2"](左のAB12が半角、右のAB12が全角)
であれば、[1 1 1 1 0 0 0 0]の様な答えが出る形です。
よろしくお願いいたします
Accepted Answer
More Answers (1)
半角カナも対象にする場合は、doubleでcharにキャストすると127を超えてしまうので、unicode2nativeでバイトに変換する方法が堅牢です。
Shift-JISだと半角が1バイト、全角が2バイトになるので、バイト数が1なら1、それ以外なら0になるようにすることで位置を特定できます。
s = ["A" "B" "1" "2" "A" "B" "1" "2" "ア" "ア" "あ"];
cell2mat(arrayfun(@(x) length(unicode2native(x, 'Shift_JIS')), s, 'UniformOutput', false)) == 1
Categories
Find more on Transmitters and Receivers in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!