Tstringlist Common operations

Source: Internet
Author: User

//tstringlist Common Methods and properties:varList:tstringlist; I:integer;beginList: = tstringlist.create; List.add (' STRINGS1 ');{Add}List.add (' Strings2 '); List.exchange (0,1);{permutation}List.insert (0,' STRINGS3 ');{Insert}I: = List.indexof (' STRINGS1 ');{The first occurrence of a position}List.sort;{sort}list.sorted: = True;{Specify sort}List.count;{Total}List.text;{text Collection}List.delete (0);{Delete, 0 is the first data}List.loadfromfile (' C:\tmp.txt ');{Open}List.savetofile (' C:\tmp.txt ');{Save}List.clear;{Empty}List.free;{Release}End;
//Read in string  var List:tstringlist; begin ' aaa,bbb,ccc,ddd ' //equivalent: List.text: = ' aaa ' + #13 # # + ' BBB ' + #13 # # ' + ' CCC ' + ' #13 # # ' + ' DDD ';  //4 ShowMessage (list[0//aaa list.free;  End;
//Displace delimiter  var List:tstringlist; begin ' | ' ' aaa|bbb|ccc|ddd '  //4 ShowMessage (list[0//aaa list.free;  End;
//Similar hash table operation methodvarList:tstringlist;beginList: = tstringlist.create; List.add (' aaa=111 '); List.add (' bbb=222 '); List.add (' ccc=333 '); List.add (' ddd=444 '); ShowMessage (list.names[1]);//bbbShowMessage (list.valuefromindex[1]);//222ShowMessage (list.values[' BBB ']);//222//valuefromindex can be assigned values:list.valuefromindex[1] :=' 2 '; ShowMessage (list[1]);//bbb=2//Can be assigned by values:list.values[' BBB '] :=' A '; ShowMessage (list[1]);//bbb=22List.free;End;
//Avoid duplicate values  var List:tstringlist;  begin  List: = tstringlist.create; List.add (' AAA'///need to specify sort first / /If duplicate value is discarded list.add (' aaa '//aaa// Duplicates has 3 selectable values://dupignore: Abort; //dupaccept: End;  //duperror: Prompt error. List.free; End;
//Sort and reverse sort{sort Function}functionDesccomparestrings (list:tstringlist; Index1, Index2:integer): Integer;beginResult: =-ansicomparetext (List[index1], list[index2]);End;procedureTform1.button1click (Sender:tobject);varList:tstringlist;beginList: = tstringlist.create; List.add (' BBB '); List.add (' CCC '); List.add (' AAA ');//Not sortedShowMessage (List.text);//BBB CCC AAA//SortList.sort; ShowMessage (List.text);//AAA BBB CCC//Inverted sortList.customsort (desccomparestrings);//Call sort functionShowMessage (List.text);//CCC BBB AAA//if:list.sorted: = True; List.add (' 999 '); List.add (' a '); List.add (' zzz '); ShowMessage (List.text);//000 999 AAA BBB CCC zzzEnd;
Cond...

Tstringlist Common operations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.