delphi将N个相同字符提取到左边,M个相同字符提取到右边


本文整理自网络,侵删。

 
比如:我有个字符串为1001110011101101011101100,我想把所有的1放在左边,所有的0放在右边,得到一个新的字符串,怎么办呢?

上代码:

uses
  StrUtils;
procedure TForm1.Button1Click(Sender: TObject);
var
  i,count0,count1:integer;
  s,str:string;
begin
  Count0 := 0;
  Count1 := 0;
  s:='1001110011101101011101100';
  for I := 1 to Length(s) do
  begin
  if s[I] = '0' then Inc(Count0);
  if s[I] = '1' then Inc(Count1);
  end;
  str:=DupeString('1',count1) + DupeString('0',count0);
  ShowMessage(str); //得到结果1111111111111110000000000
end;
这里说下DupeString函数,要uses StrUtils单元,DupeString(const AText: string; ACount: Integer)反复字符串函数,第一个参数为要反复的字符串,第二个参数为反复的个数。

相关阅读 >>

Delphi 获取android package name:

Delphi console 清屏代码

Delphi windows 编程[2] - 学习窗体生成的过程二

Delphi idhashmessagedigest, idhash, idglobal md5

Delphi tidhttp 超时的解决方案

Delphi 封装frame到dll文件

Delphi cxgrid 通过字段名取得列

Delphi中利用中断获得系统启动以来的时间

Delphi tclientdataset用法详解

Delphi实现获取密码框中的密码

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...