code:Constconstr:string = ' 0=aaa,1=bbb,2=ccc,3=ddd ';VarStrs:tstrings;I:integer;BeginSTRs: = tstringlist.create;Strs.commatext: = Constr;For I: = 0 to STRs. Count-1 doBeginShowMessage (STRs. Names);ShowMessage (STRs. Values[strs. Names]);ShowMessage (STRs. Valuefromindex);EndEndIt is not difficult to see through this example:At this time, the content in STRs is:0=aaa1=bbb2=ccc3=dddIn names, it is:0123In the values, it is:AaaBbbCccDdd=============================================================
Tstringlist class is a pair of the most factory used in Delphi, we look at the detailed usage of tstringlist here together.
Let's start by listing several properties to be discussed:1, CommaText2, Delimiter Delimitedtext3, Names Values Valuefromindex
Tstrings is an abstract class that, in actual development, is the most applied except for the basic type.
Tstringlist
reference from the list without destroying the object.
In the tstringlist, the strings are stored in one row and one row. Tstringlist. Text returns all strings. If the first, second, and third rows are \ 'aa \ ', \ 'bb \', and \ 'CC, then the text returns "\ 'aa \ '+ #13 #10 + \ 'bb \' + #13 #10 + \ 'CC \ '+ #13 #10" (No including double quotation marks ). All strings are connected by
Problem Source: http://www.cnblogs.com/del/archive/2008/04/26/973346.html#1171927
The tlist class is commonly used to store series objects in Delphi. With tobjectlist (in the contnrs unit), the storage object has a better choice, because the objects removed from the tobjectlist list will be released at the same time.
Few people use tstringlist to store objects, but they do not know that using tstringlist
The Code of others has resulted in an even-present bug. After debugging for a day and reading the following, I suddenly realized.
Without a license, programmers are stuck. I got shot while I was lying down.
======================================
Http://www.cnblogs.com/monkeyking/articles/234685.html
I worked very tired a few days ago and was a bit confused when I was writing code. I didn't hesitate to see tstringlist. Find.
TstringsIs an abstract class. In actual development, it has the most applications except the basic type.We all know the general usage. Now we will discuss some of its advanced usage.First, list the several attributes to be discussed:1. commatext2. delimiter delimitedtext3. Names Values valuefromindex
First read: commatext. How to use it? UseCodeSpeaker:ConstConstr: String = 'aaa, BBB, CCC, DDD ';VaRSTRs: tstrings;I: integer;BeginSTRs: =Tstringlist
Problem Source: http://www.cnblogs.com/del/archive/2008/12/29/1230404.html#1416838
For example, there are two tstringlist objects: list1 and list2;
List2.assign (list1) is to copy the content of list1 to list2;
List2: = list1 is equivalent to giving list1 another name.
Example:
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls; Type tform1 = Class (tf
The usage of Delphi tstringlist tstrings is an abstract class. In actual development, tstrings have the most applications besides the basic types.
We all know the general usage. Now we will discuss some of its advanced usage.
First, list the several attributes to be discussed:
1. commatext
2. delimiter delimitedtext
3. First read the names Values valuefromindex: commatext. How to use it? Use code to speak:
Const
Constr: String = 'aaa, BBB, CCC, DDD
//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.loadfromf
The data in the tstringlist is obtained by Directly Reading text files, or by using the idtcphttp protocol from the web page of the website.
VaR shtml: tstringlist;
Shtml: = tstringlist. Create;Shtml. Add (data );Icouter: = shtml. count;
Although the data contains multiple lines of text, the value of icouter is 1! To bypass this issue, add a Momo control and m
//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.loadfromf
In Delphi, The tstringlist contains a function called find. It searches for a string in a stringlist and returns the index of this string in the stringlist. Descriptions in Delphi help are as follows:
Locates the index for a string in a sorted list and indicates whether a string with that value already exists in the list.
Delphi Syntax:
Function find (const S: string; var index: integer): Boolean; virtual;
C ++ Syntax:
Virtual bool _ fastcall find (co
Delphi Tstringlist Usage DetailedTstringlist Common Methods and properties:varlist:tstringlist; I:integer;beginList:= Tstringlist.Create; List.add ('STRINGS1');{Add}List.add ('STRINGS2'); List.exchange (0,1);{Displacement}List.insert (0,'STRINGS3');{Insert}I:= List.indexof ('STRINGS1');{the first occurrence of the position}List.sort; {Sort}list.sorted:= True;{Specify sort}List.count; {Total}List.text; {Text Collection}List.delete (0);{Delete, 0 is the
1, set sorted: = TRUE;2. Add DataAdd (' 3 '); Add (' 4 '); Add (' 1 ');ShowMessage (Commatext);//1,3,43, and then modify the sorted property to False, the previously added data will not revert to the order of addition 341Adding new Data Add (' 5 ');4, ShowMessage (commatext);//1345procedure tstringlist.setsorted (Value:boolean); begin if Then begin if Then Sort; When you modify the sorted property, only the new value is true, and the new value is false when fsorted is not sorted:= Value; End
Tstringlist Common operations//Tstringlist Common Methods and properties:VarList:tstringlist; I:integer;BeginList: =Tstringlist.create; List.add (‘Strings1‘);{Add to}List.add (‘Strings2‘); List.exchange (0,1);{Replacement}List.insert (0,‘Strings3‘);{Insert}I: = List.indexof (‘Strings1‘);{The first occurrence of the position}List.sort;{Sort}list.sorted: = True;{Specify sort}List.count;{Total}List.text;{Text
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.