• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++Builder也有StringBuilder

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

    System::Sysutils::TStringBuilder *sb = new TStringBuilder;
    sb->Append("ww");
    sb->AppendLine();
    sb->Append("hello");
    Caption = sb->ToString();
    delete sb;

c++builder字符串处理类

 sb->Append("ww"); 这里重载了很多类型,int、bool、byte等,无需自己转换了。

StringWriter.write();//同样重载了很多方法。

 

TStringBuilder、TStringReader、TStringWriter

http://docwiki.embarcadero.com/Libraries/Berlin/en/System.SysUtils.TStringBuilder

http://docwiki.embarcadero.com/CodeExamples/Berlin/en/StringReaderWriter_(C%2B%2B)

 http://docwiki.embarcadero.com/CodeExamples/Berlin/en/TStringBuilder_(C%2B%2B)

 

网友整理的很实用

http://www.cnblogs.com/sures/p/6044917.html

 

很实用的方法

TStringBuilder* Replace(UnicodeString OldValue, UnicodeString NewValue, int StartIndex, int Count)/* overload */;

    std::auto_ptr<TStringBuilder> sb(new TStringBuilder());

 

 

void __fastcall TMainForm::btReadClick(TObject *Sender)
{
  Char Ch;
  TStringReader* Reader1;
  TStringReader* Reader2;
  TCharArray Buffer;
  String Line;
  String Init;
 
  Init = String("This is the first line") + char(13) + "This is the some text";
 
  /* Create a string reader. */
  Reader1 = new TStringReader(Init);
  Reader2 = new TStringReader(Init);
 
  /* Read the first string. */
  Edit1->Text = Reader1->ReadLine();
  Memo1->Text = Reader1->ReadToEnd();
 
  /* Prepare a buffer. */
  Buffer.set_length(23);
 
  /* Read first 23 characters from the second string. */
  if (Reader2->ReadBlock(Buffer,0,Buffer.Length) < Buffer.Length)
  {
    MessageDlg("Reading failed! Expected to read 23 characters!",
      mtError, TMsgDlgButtons() << mbOK, 0);
  }
 
  /* Read the rest of the second string, char-by-char, and write it in the
     second memo box. */
  Line = "";
  do
  {
      Ch = Char(Reader2->Read());
      Line += Ch;
  }
  while (Reader2->Peek() >= 0);
  Memo2->Text = Line;
 
  /* Close the reader. */
  Reader1->Close();
  Reader2->Close();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::btWriteClick(TObject *Sender)
{
  TStringWriter* Writer;
  String MyStr;
 
  /* Create a string writer. */
  Writer = new TStringWriter();
 
  /* Store the text in the writer. */
  Writer->WriteLine(Edit1->Text);
  Writer->Write(Memo1->Text + sLineBreak + Memo2->Text);
  MyStr = Writer->ToString();
  ShowMessage(MyStr);
 
  /* Clear writer's buffer data. */
  Writer->Flush();
 
  /* Close the writer. */
  Writer->Close();
  delete Writer;
}

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap