Visual C++ .NET/Development/StringWriter

Материал из .Net Framework эксперт
Версия от 12:04, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Convert StringWriter to String

 
#include "stdafx.h"
#using "System.Windows.Forms.dll"
using namespace System;
using namespace System::IO;
using namespace System::Text;
using namespace System::Windows::Forms;
int main()
{
   StringWriter^ sw = gcnew StringWriter();
   sw->WriteLine("asdf");
   sw->Write("asdf\n");
   sw->WriteLine();
   String^ jambo = "asdf";
   String^ s = String::Format("{0}, {1}.", jambo, jambo);
   sw->WriteLine(s);
   sw->Write("Make a wish, {0}, {0}.", jambo);
   s = "asdf.\n";
   String::Concat(s, "asdf?");
   sw->WriteLine(s);

   StringBuilder^ sb = gcnew StringBuilder();
   sb->Append("asdf\n");
   sw->WriteLine(sb);
   // The resulting string might be displayed to the user in a GUI
   MessageBox::Show(sw->ToString(), "Poetry", MessageBoxButtons::OK);
}


Using StringWriter to write string

 
#include "stdafx.h"
#using "System.Windows.Forms.dll"
using namespace System;
using namespace System::IO;
using namespace System::Text;
using namespace System::Windows::Forms;
int main()
{
   StringWriter^ sw = gcnew StringWriter();
   sw->WriteLine("asdf");
   sw->Write("asdf\n");
   sw->WriteLine();
   String^ jambo = "asdf";
   String^ s = String::Format("{0}, {1}.", jambo, jambo);
   sw->WriteLine(s);
   sw->Write("Make a wish, {0}, {0}.", jambo);
   s = "asdf.\n";
   String::Concat(s, "asdf?");
   sw->WriteLine(s);

   StringBuilder^ sb = gcnew StringBuilder();
   sb->Append("asdf\n");
   sw->WriteLine(sb);
   // The resulting string might be displayed to the user in a GUI
   MessageBox::Show(sw->ToString(), "Poetry", MessageBoxButtons::OK);
}