Deividas Kiznis
Deividas Kiznis

Reputation: 72

How to split sentence in visual c++?

Hi I'm currently using Microsoft Visual Studio 2015, c++ with forms and having trouble with split. I have tried many code exemples (all of them was on console application and I didn't know how to make them work for me). This is how at least I imagining code (simplified code exemple below). There is a string that you take from textBox1, then you split that string where there is a dot, and putting them in table.

String ^ text = textBox1->Text;
text->ToString()->Split('.');
tableGrid->Rows[0]->Cells[1]->Value = text;

Upvotes: 0

Views: 1149

Answers (1)

jschroedl
jschroedl

Reputation: 4986

Split does not modify text here. Instead it returns an array of the split results.

You need to capture and use the results so something like this:

String^ text = textBox1->Text;
cli::array<String^>^ pieces = text->Split('.');
for (int i = 0; i < pieces->Length; ++i) {
    // Add pieces[i] to the table. Perhaps:
    tableGrid->Rows[0]->Cells[i]->Value = pieces[i];

}

Upvotes: 1

Related Questions