0

私は今日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();

代わりに次のようにするにはどうすればよいですか?それぞれの名前について、

dn: CN=Schytt LCPL Zach,DC=Sample,DC=Site
changetype: add
displayName: Schytt.Zach

調べてみましたがinsert、よくわかりません。

4

1 に答える 1

1

このようなものをお探しですか?

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();
于 2013-01-22T04:46:07.387 に答える