全角文字と半角文字を判別する方法を教えていただきたいです。
Afficher commentaires plus anciens
MATLABで全角文字と半角文字を判別する方法を教えていただきたいでしょうか。
例えば、["A" "B" "1" "2" "A" "B" "1" "2"](左のAB12が半角、右のAB12が全角)
であれば、[1 1 1 1 0 0 0 0]の様な答えが出る形です。
よろしくお願いいたします
Réponse acceptée
Plus de réponses (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
1 commentaire
丈太郎 森川
le 23 Mar 2022
Catégories
En savoir plus sur 環境と設定 dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!