XE4 TStringDynArray 比 c6 的TStringList 好用 字符串 分解 分割 转换 TByteDynArray

时间:2020-12-26 15:29:01

TStringDynArray 动态数组  字符串 分解 分割  System::DynamicArray<System::UnicodeString>

TByteDynArray,    (TIdBytes)    String  相互转换  DynamicArray<System::Byte>

TIdBytes = array of Byte;

TByteDynArray;

Delphi   type TByteDynArray = array of Byte;

TByteDynArray defines a dynamic array of byte elements. You must use SetLength to allocate storage for such an array.

typedef DynamicArray<Byte>            TByteDynArray;
TBytes,就是 typedef System::DynamicArray<System::Byte> TBytes;

TBytes和TByteDynArray 是等价的。

数组

System::DynamicArray<int> array { 1, 2, 3, 4, 5};

DynamicArray<int> aint;
aint.Low;
aint.High;
aint[];
  1. arrayOfInt.Length = 10;
int total=;
for (int i=aint.Low; i<=aint.High; i++)
total += aint[i];
return total
SplitString 函数
#include <System.StrUtils.hpp>
TStringDynArray __fastcall SplitString(UnicodeString S, UnicodeString Delimiters);
和stringList的Delimiter一样,空格也分割了。

TByteArray 

#include <System.StrUtils.hpp>
#include <System.SysUtils.hpp>
 
TStringDynArray ls; 
ls = SplitString("a|b|c","|");
for(int i = ; i < ls .Length; i++)
ShowMessage(ls [i]);     TStringDynArray sarr;
    TStringList *ls = new TStringList();
    ls->Text = "a|b|c";
    sarr = ls->ToStringArray();
    delete ls; //String <==> TByteDynArray
String str;
str="abc";
    TByteDynArray barr;
    barr = str.BytesOf(); bytes=System::Sysutils::BytesOf(Caption);
bytes=System::Sysutils::WideBytesOf(Caption); Caption = System::Sysutils::StringOf(barr);
Caption = System::Sysutils::WideStringOf(barr);

TBytes bytes;

TByteDynArray barr;

String str;

str = Memo1->Text;

barr = str.BytesOf();

bytes = BytesOf(str);

bytes = WideBytesOf(str);

bytes = barr;

ExtractStrings

int __fastcall ExtractStrings(const System::Sysutils::TSysCharSet &Separators, const System::Sysutils::TSysCharSet &WhiteSpace, System::WideChar * Content, TStrings* Strings);

TStringDynArray  ar;  ar[0]=2;  ar[25]="";  ar.set_length(28);  ar[0]=2;  ar.Length;

用指定的字符串分割,空格可以不分割!

  ExtractStrings([';',',',':'],['#',' '],PChar(s),List);
  //第一个参数是分隔符; 第二个参数是开头被忽略的字符
  1. TStringDynArray arr;
  2. arr = System::Ioutils::TDirectory::GetFiles("C:\\Windows");
  3. this->Memo1->Lines->AddStrings(arr);
	TStringDynArray arr;
arr = System::Ioutils::TDirectory::GetFiles("C:\\Windows");
this->Memo1->Lines->AddStrings(arr);
  1. arr = System::Ioutils::TDirectory::GetFiles("c:\\windows","*.ppt", System::Ioutils::TSearchOption::soAllDirectories );
 for I := 0 to Length(LList) - 1 do
mmResults.Lines.Add(LList[I]);
 

Delphi 推荐用这个方法

astr:string;
  list: TArray<string>;
  list := astr.Split(['|']);
  list[0],list[1]...

for i := 0 to High(Editors) do

list[i]

for s in list

showmessage(s);

Split 是 delphi的函数,c++没有。TStringHelper = record helper for string

TStringList好用的特性
ss:TStringList;
begin
ss.AddPair('p1','aaaaa');
ss.AddPair('p2','bbbbb');
ss.Values['p1'];
ss.Values['p2'];

这样的效果

p1=aaaaa
p2=bbbbb

取p1的值aaaa

ss.Values['p1'];

st.Split([','],TStringSplitOptions.ExcludeEmpty);
CommaText甚是方便
TStrings.CommaText
aa
bb
cc
返回值 aa,bb,cc TStringList分割字符
新属性StrictDelimiter精确分割,空格不在分割换行了。         slsub->StrictDelimiter=true;
        slsub->Delimiter = awchar;
        slsub->DelimitedText = str; 拼接
list:TStringList;
Result := string.Join('|',List.ToStringArray) ;