Visual C++ .NET/Development/StringWriter

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

Convert StringWriter to String

<source lang="csharp">

  1. include "stdafx.h"
  2. 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);

}

 </source>


Using StringWriter to write string

<source lang="csharp">

  1. include "stdafx.h"
  2. 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);

}

 </source>