Você está na página 1de 2

How to: Split Strings (C# Programming Guide)

http://msdn.microsoft.com/en-us/library/ms228388

How to: Split Strings (C# Programming Guide)


Visual Studio 2010 This topic has not yet been rated - Rate this topic The following code example demonstrates how a string can be parsed using the String.Split method. As input, Split takes an array of chars that indicate which characters are to be used as delimiters. In this example, spaces, commas, periods, colons, and tabs are used. An array containing these delimiters is passed to Split, and each word in the sentence is displayed separately using the resulting array of strings.

Example

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 7 words in text: one two three four five six seven */

two three:four,five six seven'

See Also
Concepts

1 of 2

5/25/2012 11:48 AM

How to: Split Strings (C# Programming Guide) C# Programming Guide Other Resources Strings (C# Programming Guide) .NET Framework Regular Expressions .NET Programming Guide

http://msdn.microsoft.com/en-us/library/ms228388

Did you find this helpful?

Yes

No

Community Content
2012 Microsoft. All rights reserved.

2 of 2

5/25/2012 11:48 AM

Você também pode gostar