LoginSignup
0
1

More than 5 years have passed since last update.

iOSで文字の全角判定

Posted at

文字が全角かどうかの判定を、iOSで確認する

  • 文字が全角かどうかを判定する処理
Utilities.cs
using System.Text;
public class TextUtility
{
    public static bool IsZenkaku(string moji)
    {
        return GetByteCount(moji) == moji.Length * 2;
    }
    public static bool IsHankaku(string moji)
    {
        return GetByteCount(moji) == moji.Length;
    }
    public static int GetByteCount(string text)
    {
        return Encoding.GetEncoding("Shift_JIS").GetByteCount(text);
    }
}
  • 使い方
if (TextUtility.IsZenkaku("あ")) {
    Debug.Log("全角です");
}

エディタ上では動作しますが、iOSプロジェクトではエラーになります。

エラーを回避する

  • エラーの原因はDDLが見つからない
    行方不明のDLL(I18N.dll, I18N.CJK.dll)をプロジェクトのAssets/Plugins フォルダにコピーする。

  • DLLの場所
    Unity.app/Contents/Frameworks/Mono/lib/mono/unity

  • 問題点
    Unicodeにしか存在しない文字は今のところ判定できない

0
1
1

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
1