ASP.NET 전화번호 구분자로 반환
'-' 구분자가 있으면 구분자로 1,2,3번째 자리를 '|'로 구분하여 반환한다.
'-' 구분자가 없으면 9,10,11자리별로 '|'로 구분하여 반환한다.
/// <summary>
/// 전화번호 구분자로 반환
/// </summary>
/// <param name="full"></param>
/// <returns></returns>
public string GetPhoneNumber(string full)
{
string ret = string.Empty;
if (!String.IsNullOrWhiteSpace(full) && full.Contains("-")) //010-123-1234, 010-1234-5678, 02-123-1234...
{
ret = full.Substring(0, full.IndexOf("-"));
ret += "|" + full.Substring(full.IndexOf("-") + 1, (full.LastIndexOf("-") - full.IndexOf("-") - 1));
ret += "|" + full.Substring(full.LastIndexOf("-") + 1);
}
else
{
if (full.Length == 9) //021231234
{
ret = full.Substring(0, 2);
ret += "|" + full.Substring(2, 3);
ret += "|" + full.Substring(5, 4);
}
else if (full.Length == 10) //0101231234
{
ret = full.Substring(0, 3);
ret += "|" + full.Substring(3, 3);
ret += "|" + full.Substring(6, 4);
}
else if (full.Length == 11) //01012345678
{
ret = full.Substring(0, 3);
ret += "|" + full.Substring(3, 4);
ret += "|" + full.Substring(7, 4);
}
else
{
ret = "";
}
}
return ret;
}