Visual C++ .NET/Development/StringBuilder — различия между версиями

Материал из .Net Framework эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 12:04, 26 мая 2010

Add string to StringBuilder

 
#include "stdafx.h"
using namespace System;
using namespace System::IO;
using namespace System::Text;
int main(array<System::String ^> ^args)
{
    StringBuilder ^tmppath = gcnew StringBuilder();
    tmppath->Append("c:\\");
    tmppath->Append(" ");
    String ^path = tmppath->ToString()->Trim();

    return 0;
}


Append char array to StringBuilder

 
#include "stdafx.h"
using namespace System;
using namespace System::Text;
int main()
{
   StringBuilder^ sb = gcnew StringBuilder("C", 30);
   sb->Append(gcnew array<Char>{"+","+"});
   sb->Append("/CLI.");
   sb->Insert(0, "asdf ");
   sb->Replace(".","!");
   Console::WriteLine( sb->ToString() );
}


Append to StringBuilder

 
#include "stdafx.h"
using namespace System;
using namespace System::Text;
int main()
{
   StringBuilder^ sb = gcnew StringBuilder("C", 30);
   sb->Append(gcnew array<Char>{"+","+"});
   sb->Append("/CLI.");
   sb->Insert(0, "asdf ");
   sb->Replace(".","!");
   Console::WriteLine( sb->ToString() );
}


Convert StringBuilder to String

 
#include "stdafx.h"
using namespace System;
using namespace System::Text;
int main()
{
   StringBuilder^ sb = gcnew StringBuilder("C", 30);
   sb->Append(gcnew array<Char>{"+","+"});
   sb->Append("/CLI.");
   sb->Insert(0, "asdf ");
   sb->Replace(".","!");
   Console::WriteLine( sb->ToString() );
}


Insert String to StringBuilder

 
#include "stdafx.h"
using namespace System;
using namespace System::Text;
int main()
{
   StringBuilder^ sb = gcnew StringBuilder("C", 30);
   sb->Append(gcnew array<Char>{"+","+"});
   sb->Append("/CLI.");
   sb->Insert(0, "asdf ");
   sb->Replace(".","!");
   Console::WriteLine( sb->ToString() );
}


Replace String in StringBuilder

 
#include "stdafx.h"
using namespace System;
using namespace System::Text;
int main()
{
   StringBuilder^ sb = gcnew StringBuilder("C", 30);
   sb->Append(gcnew array<Char>{"+","+"});
   sb->Append("/CLI.");
   sb->Insert(0, "asdf ");
   sb->Replace(".","!");
   Console::WriteLine( sb->ToString() );
}