判断半角或全角字符(包括日文,数字,字母等,任何半角全角的区分)
说 明:Encoding.Default.GetByteCount(c.ToString());会返回字符占用的空间个数,返回1表示半角,返回2表示 全角,测试通过
/// <summary>
/// 根据GetByteCount返回的值判断半角和全角
/// </summary>
/// <param name="a"></param>
/// <returns></returns>
public static bool IsAllBanjiaoJapan(string parStr, string parMsg)
{
foreach (char c in parStr.ToCharArray())
{
int k = Encoding.Default.GetByteCount(c.ToString()); //k=1 半角 k=2全角
if(k==2)
{
FormMessage.ShowAlert(parMsg + FormMessage.Input_BanJiaoPianJiaoMing);
return false;
}
}
return true;
}
/// <summary>
/// 根据GetByteCount返回的值判断半角和全角
/// </summary>
/// <param name="a"></param>
/// <returns></returns>
public static bool IsAllBanjiaoJapan(string parStr, string parMsg)
{
foreach (char c in parStr.ToCharArray())
{
int k = Encoding.Default.GetByteCount(c.ToString()); //k=1 半角 k=2全角
if(k==2)
{
FormMessage.ShowAlert(parMsg + FormMessage.Input_BanJiaoPianJiaoMing);
return false;
}
}
return true;
}