Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.
The latest version of this topic can be found at How to: Parse Strings Using the Split Method (C++/CLI).
The following code example demonstrates using the String.Split method to extract each word from a string. A string containing multiple types of word delineators is constructed and then parsed by calling Split with a list of the delineators. Then, each word in the sentence is displayed separately.
Example
// regex_split.cpp
// compile with: /clr
using namespace System;
int main()
{
String^ delimStr = " ,.:\t";
Console::WriteLine( "delimiter : '{0}'", delimStr );
array<Char>^ delimiter = delimStr->ToCharArray( );
array<String^>^ words;
String^ line = "one\ttwo three:four,five six seven";
Console::WriteLine( "text : '{0}'", line );
words = line->Split( delimiter );
Console::WriteLine( "Number of Words : {0}", words->Length );
for (int word=0; word<words->Length; word++)
Console::WriteLine( "{0}", words[word] );
return 0;
}
See Also
.NET Framework Regular Expressions
.NET Programming with C++/CLI (Visual C++)