Delphi 处理以逗号分隔的长字符串


本文整理自网络,侵删。

 
方法1:

procedure Str_Tools;
var
    TmpList:TStringList;
    IIndex:Integer;
    MUSVOL:String;
begin
    MUSVOL:='0,2,4,6,8,10';
    TmpList:=TStringList.Create;
    try
        while Pos(',',MUSVOL)>0 do
        begin
            IIndex:=Pos(',',MUSVOL);
            TmpList.Add(Copy(MUSVOL,1,IIndex-1));
            Delete(MUSVOL,1,IIndex);
        end;
        TmpList.Add(MUSVOL);
        showmessage(TmpList.Strings[1]);
   finally
        TmpList.free;
   end;
end;


方法2:
procedure Str_Tools2;
var
    I:integer;
    bol:Boolean;
    MUSLIST:Tstringlist;
    Dsp_MusicVol:array [0..6]of integer;
begin
    try
    MUSLIST:=Tstringlist.Create;
MUSLIST.CommaText:='1,3,5,7,9,11';
        for i:=0 to 6 do
        begin
           if (MUSLIST.Count>=i-1) then  Dsp_MusicVol[i]:=strtoint(MUSLIST[i]);
           showmessage(Dsp_MusicVol[i]);
        end;
        
    finally
        MUSLIST.free;
    end;
 
end;

相关阅读 >>

Delphi xe7使用本身的md5单元进行字符串加密

Delphi 把流中的字符串转换为 utf 格式

Delphi中如何用一个按钮控制开与关两个状态

Delphi 代替pos的函数

Delphi10.3读取json数据

Delphi 随机生成汉字

Delphi eof 判断文件指针是否移动到了文件未尾

Delphi opendialog1 打开多个文件

Delphi 控制台读写

Delphixe win7、mssql2000、udl

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



打赏

取消

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

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

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

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

评论

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