C# 문자열을 분리하기

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

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

01string[] strTemp = textBox1.Text.Split(new char[] {':'});
02 
03if (strTemp.Length >= 2)
04{
05    try
06    {
07        int a = Convert.ToInt32(strTemp[0]);
08        int b = Convert.ToInt32(strTemp[1]);
09        MessageBox.Show(a.ToString() + ", " + b.ToString());
10    }
11 
12    catch (Exception except)
13    {
14        MessageBox.Show(except.Message);
15    }
16}
Posted by 아르다