C++;Stringbuilder插入、反转和重新排列多个字符串

C++;Stringbuilder插入、反转和重新排列多个字符串,string,c++-cli,stringbuilder,String,C++ Cli,Stringbuilder,我今天学习了Stringbuilder,一直在胡闹,因为它可能是我需要做的最简单或最快的方法 我有这样一个文本文件: Zach LCPL Schytt Bill CPL John Mark LCPL Simmons ...etc 我使用下面的函数将其从列表框读取到文本框 StringBuilder^ sb = gcnew StringBuilder(); Convertor^ form2 = gcnew Convertor(); for (int i =

我今天学习了Stringbuilder,一直在胡闹,因为它可能是我需要做的最简单或最快的方法

我有这样一个文本文件:

Zach LCPL Schytt
Bill CPL John
Mark LCPL Simmons
...etc
我使用下面的函数将其从列表框读取到文本框

StringBuilder^ sb = gcnew StringBuilder();
        Convertor^ form2 = gcnew Convertor();
            for (int i = 0; i < listBox1->Items->Count; i++){
                String^ temp = listBox1->Items[i]->ToString();
                sb->AppendFormat("{0}", temp)->AppendLine();
            }
            form2->textBox1->Text = sb->ToString();
            form2->ShowDialog();

我查看了
insert
,还有一些东西,但不太明白。

你在找这样的东西吗

StringBuilder^ sb = gcnew StringBuilder();
for (int i = 0; i < listBox1->Items->Count; i++)
{
    String^ temp = listBox1->Items[i]->ToString();

    // First, separate the input string.
    array<String^>^ strings = temp->Split();
    String^ firstName = strings[0];
    String^ rank = strings[1];
    String^ lastName = strings[2];

    // Then build the output string. (Remember that the C++ compiler 
    // concatenates strings at compile time, so we don't need a plus sign.)
    sb->AppendFormat("dn: CN = {2} {3} {1},DC=Sample,DC=Site{0}"
                     "changetype: add{0}"
                     "displayName: {2}.{1}{0}", 
                     Environment::Newline, //0
                     firstName, //1
                     lastName, //2
                     rank); //3
}

form2->textBox1->Text = sb->ToString();
form2->ShowDialog();
StringBuilder^sb=gcnew StringBuilder();
对于(int i=0;iItems->Count;i++)
{
字符串^temp=listBox1->Items[i]->ToString();
//首先,分离输入字符串。
数组^strings=temp->Split();
String^firstName=strings[0];
字符串^rank=字符串[1];
字符串^lastName=strings[2];
//然后构建输出字符串。(记住C++编译器
//在编译时连接字符串,因此不需要加号。)
sb->AppendFormat(“dn:CN={2}{3}{1},DC=Sample,DC=Site{0}”
“changetype:添加{0}”
“显示名称:{2}.{1}{0}”,
Environment::Newline,//0
名字,//1
姓氏,//2
秩);//3
}
form2->textBox1->Text=sb->ToString();
form2->ShowDialog();

这正是我想要的。你知道哪里有好的教程可以学习更多关于字符串如何工作的知识吗?String ^rank=strings[1]抛出一个系统。未处理IndexAutoFrangeException
StringBuilder^ sb = gcnew StringBuilder();
for (int i = 0; i < listBox1->Items->Count; i++)
{
    String^ temp = listBox1->Items[i]->ToString();

    // First, separate the input string.
    array<String^>^ strings = temp->Split();
    String^ firstName = strings[0];
    String^ rank = strings[1];
    String^ lastName = strings[2];

    // Then build the output string. (Remember that the C++ compiler 
    // concatenates strings at compile time, so we don't need a plus sign.)
    sb->AppendFormat("dn: CN = {2} {3} {1},DC=Sample,DC=Site{0}"
                     "changetype: add{0}"
                     "displayName: {2}.{1}{0}", 
                     Environment::Newline, //0
                     firstName, //1
                     lastName, //2
                     rank); //3
}

form2->textBox1->Text = sb->ToString();
form2->ShowDialog();