월별 글 목록: 2013년 4월월

C# 문자열 분할 하기 ( String.Split)

class TestStringSplit
{
    static void Main()
    {
        char[] delimiterChars = { ' ', ',', '.', ':', '\t' };
 
        string text = "one\ttwo three:four,five six seven";
        System.Console.WriteLine("Original text: '{0}'", text);
 
        string[] words = text.Split(delimiterChars);
        System.Console.WriteLine("{0} words in text:", words.Length);
 
        foreach (string s in words)
        {
            System.Console.WriteLine(s);
        }
 
        // Keep the console window open in debug mode.
        System.Console.WriteLine("Press any key to exit.");
        System.Console.ReadKey();
    }
}
/* Output:
    Original text: 'one     two three:four,five six seven'
    7 words in text:
    one
    two
    three
    four
    five
    six
    seven
 */
 
// 요기 까지는  MSDN 에 있는 내용  좀더 쉽게..
 
 
strInData = "-000.66 000.59-000.95-000.06 0745.1 0000.0";  
//  잘라낼 문자열 전체 
 
char[] delimiterChars = { ' ', '-' };   
// 문자열에서  공백 과 - 문자로 구분
 
string[] words = strInData.Split(delimiterChars);   
  // 해당 구분자로 문자열을 구분 시키는 라인
 
// 결과  
words[0]= ""
words[1]= "000.66"
words[2]= "000.59"
words[3]= "000.95"
words[4]= "000.06" 
words[5]= "0745.1"
words[6]= "0000.0"
 
// 이상  해피한 코딩 하세요~~!!!!