특정 string 이 한글인지 영문인지 판별하는 코드
using System.Collections.Generic;
using System.Globalization;
using System.Collections;
namespace WindowsApplication3
{
static class Program
{
static void Main()
{
string testKorean = "abcd한글";
string testDigit = "abc123";
string testSymbol ="\\*&";
string testSpace = "abc def";
PrintCategory(testKorean, GetCodeType(testKorean));
PrintCategory(testDigit, GetCodeType(testDigit));
PrintCategory(testSymbol, GetCodeType(testSymbol));
PrintCategory(testSpace, GetCodeType(testSpace));
}
static UnicodeCategory[] GetCodeType(string str)
{
if (string.IsNullOrEmpty(str))
{
return null;
}
else
{
List<UnicodeCategory> m_listUnicodeInfo = new List<UnicodeCategory>();
for(int i=0; i<str.Length; i++)
{
UnicodeCategory category = CharUnicodeInfo.GetUnicodeCategory(str[i]);
if(m_listUnicodeInfo.Contains(category) == false)
{
m_listUnicodeInfo.Add(category);
}
}
return m_listUnicodeInfo.ToArray();
}
}
static void PrintCategory(string str, UnicodeCategory[] categories)
{
System.Console.WriteLine(str + " : ");
if(categories != null)
{
for(int i=0; i<categories.Length; i++)
{
System.Console.Write(categories[i].ToString() + ", ");
}
System.Console.WriteLine();
}
}
}

Prev

Rss Feed