'문자열'에 해당되는 글 3건

  1. 2009.08.07 C# 문자열을 분리하기 by 아르다

C# 문자열을 분리하기

C#/Tip : 2009. 8. 7. 11:40

예를 들어서 15:12 라는 문자변수를 15와 12를 따로 저장할때 사용하는 방법 

string[] strTemp = textBox1.Text.Split(new char[] {':'});

if (strTemp.Length >= 2)
{
    try
    {
        int a = Convert.ToInt32(strTemp[0]);
        int b = Convert.ToInt32(strTemp[1]);
        MessageBox.Show(a.ToString() + ", " + b.ToString());
    }

    catch (Exception except)
    {
        MessageBox.Show(except.Message);
    }
}
Posted by 아르다