Rapid-Q Documentation by William Yu (c)1999 Appendix A: QSTRINGLIST

QSTRINGLIST Component

QStringList is a non-visible component to store and manipulate a list of strings.

QStringList Properties
Field Type R/W Default Support





Duplicates INTEGER RW dupIgnore W
Item ARRAY of STRING  (index starts at 0 RW
WXG
ItemCount INTEGER R
WXG
Sorted INTEGER RW False W
Text STRING RW
WXG

QStringList Methods
Method Type Description Params Support





AddItems SUBI Add strings to stringlist STRINGs, Infinite WXG
AddList SUB (List AS QStringList) Append another stringlist 1 WXG
Build FUNCTION Build(Start%, End%, Delim$) AS STRING Returns a deliminated string 3 WXG
Clear SUB Clears entire stringlist 0 WXG
DelItems SUBI Delete strings by their index Index #s, Infinite WXG
Exchange SUB (Index1%, Index2%) Swap strings at Index1% with Index2% 2 WXG
IndexOf FUNCTION IndexOf%(String$) Return Index number of string 1 WXG
InsertItem SUB (Index%, String$) Insert string at Index%,.
Index% must be within bounds.of ItemCount
2 WXG
LoadFromFile SUB (File$) Load text file in stringlist 1 WXG
LoadFromStream SUB (File AS QStream) Load file/memorystream in stringlist 1 W
Parse FUNCTION Parse(Source$, Delim$) AS LONG Separates strings by the Delim$ and stores each item in the list 2 WXG
SaveToFile SUB (File$) Saves stringlist to file 1 WXG
SaveToStream SUB (File AS QStream) WARNING: Saving to a MemorySteam does not work and erases the StringList!!
1 W
Sort SUB Sort the stringlist 0 WXG

QStringList Events
Event Type Occurs when... Params




Note,  indexes in QStringList are zero based:

Dim MyStringList As QStringList
Dim TestString As String
MyStringList.AddItems("a","b","c")
TestString = MyStringList.Item(MyStringList.ItemCount) '<- this is wrong
TestString = MyStringList.Item(MyStringList.ItemCount-1) '<-correct

'you subtract 1 to reference the last item


QStringList Examples
  DIM StringList1 AS QStringList
DIM StringList2 AS QStringList

StringList1.AddItems "Oranges","Apples"
StringList2.AddItems "Byte","Word","Integer"
StringList1.AddList(StringList2)
StringList1.Sort

?StringList1.Text
?StringList1.Item(3)
?StringList1.IndexOf("Word")
?StringList1.IndexOf("hi")

'-------------------------------------------------------

DIM StringList AS QSTRINGLIST

StringList.Parse("James:Brown:555-3454:House",":")

PRINT StringList.Build(0,StringList.ItemCount-1,",")

'____________________________________________________________
QStringList is very fast, a lot faster than QFileStream.ReadBinStr

FUNCTION LoadString(FileName as STRING) AS string
DIM fileStr as QFileStream
result="0"
if fileStr.open (FileName,0 )=-1 then
result="-1"
result=FileStr.ReadBinStr( FileStr.size)
FileStr.Close
end if
END FUNCTION

'******************************'
$INCLUDE "RAPIDQ.INC"
'--- Declarations ---
dim SList as QStringList
'print "create string", time$
'for i =0 to 500
'ss0$=ss0$+string$(2000,"a")
'next
'print "begin to save string",time$
'SaveString(ss0$,"large01.txt")
print "begin to load string ",time$ 
SList.loadfromfile("large02.txt")
print "Loaded 2.. ",time$
print"len SList.text=";len(SList.text)

ss$=LoadString("large02.txt")
print "Loaded.. ",time$
print"len ss$=";len(ss$)
'------------------------

RESULT:

begin to load string 08:49:36
Loaded 2.. 08:49:36
len SList.text=28005603
Loaded.. 08:49:45
len ss$=28005601

Loading 28 Mb txt file
loadfromfile <1sec
ReadBinStr ~11 sec


Prev Component Contents Next Component