1 <?xml version=
"1.0" encoding=
"UTF-8"?>
2 <!DOCTYPE script:module PUBLIC
"-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3 <script:module xmlns:
script=
"http://openoffice.org/2000/script" script:
name=
"Strings" script:
language=
"StarBasic">Option Explicit
4 Public sProductname as String
7 ' Deletes out of a String
'BigString
' all possible PartStrings, that are summed up
8 ' in the Array
'ElimArray
'
9 Function ElimChar(ByVal BigString as String, ElimArray() as String)
11 For i =
0 to Ubound(ElimArray)
12 BigString = DeleteStr(BigString,ElimArray(i)
18 ' Deletes out of a String
'BigString
' a possible Partstring
'CompString
'
19 Function DeleteStr(ByVal BigString,CompString as String) as String
20 Dim i%, CompLen%, BigLen%
21 CompLen = Len(CompString)
24 i = Instr(i, BigString,CompString)
26 BigLen = Len(BigString)
27 BigString = Mid(BigString,
1,i-
1) + Mid(BigString,i+CompLen,BigLen-i+
1-CompLen)
34 ' Finds a PartString, that is framed by the Strings
'Prestring
' and
'PostString
'
35 Function FindPartString(BigString, PreString, PostString as String, SearchPos as Integer) as String
36 Dim StartPos%, EndPos%
37 Dim BigLen%, PreLen%, PostLen%
38 StartPos = Instr(SearchPos,BigString,PreString)
39 If StartPos
<> 0 Then
40 PreLen = Len(PreString)
41 EndPos = Instr(StartPos + PreLen,BigString,PostString)
42 If EndPos
<> 0 Then
43 BigLen = Len(BigString)
44 PostLen = Len(PostString)
45 FindPartString = Mid(BigString,StartPos + PreLen, EndPos - (StartPos + PreLen))
46 SearchPos = EndPos + PostLen
48 Msgbox(
"No final tag for
'" & PreString
& "' existing
",
16, GetProductName())
49 FindPartString =
""
52 FindPartString =
""
57 ' Note iCompare =
0 (Binary comparison)
58 ' iCompare =
1 (Text comparison)
59 Function PartStringInArray(BigArray(), SearchString as String, iCompare as Integer) as Integer
60 Dim MaxIndex as Integer
62 MaxIndex = Ubound(BigArray())
64 If Instr(
1, BigArray(i), SearchString, iCompare)
<> 0 Then
65 PartStringInArray() = i
69 PartStringInArray() = -
1
73 ' Deletes the String
'SmallString
' out of the String
'BigString
'
74 ' in case SmallString
's Position in BigString is right at the end
75 Function RTrimStr(ByVal BigString, SmallString as String) as String
76 Dim SmallLen as Integer
78 SmallLen = Len(SmallString)
79 BigLen = Len(BigString)
80 If Instr(
1,BigString, SmallString)
<> 0 Then
81 If Mid(BigString,BigLen +
1 - SmallLen, SmallLen) = SmallString Then
82 RTrimStr = Mid(BigString,
1,BigLen - SmallLen)
92 ' Deletes the Char
'CompChar
' out of the String
'BigString
'
93 ' in case CompChar
's Position in BigString is right at the beginning
94 Function LTRimChar(ByVal BigString as String,CompChar as String) as String
96 BigLen = Len(BigString)
98 If Left(BigString,
1) = CompChar then
99 BigString = Mid(BigString,
2,BigLen-
1)
101 ElseIf BigLen =
1 Then
102 BigString =
""
104 LTrimChar = BigString
108 ' Retrieves an Array out of a String.
109 ' The fields of the Array are separated by the parameter
'Separator
', that is contained
111 ' The Array MaxIndex delivers the highest Index of this Array
112 Function ArrayOutOfString(BigString, Separator as String, Optional MaxIndex as Integer)
113 Dim LocList() as String
114 LocList=Split(BigString,Separator)
116 If not isMissing(MaxIndex) then maxIndex=ubound(LocList())
118 ArrayOutOfString=LocList
122 ' Deletes all fieldvalues in one-dimensional Array
123 Sub ClearArray(BigArray)
125 For i = Lbound(BigArray()) to Ubound(BigArray())
126 BigArray(i) =
""
131 ' Deletes all fieldvalues in a multidimensional Array
132 Sub ClearMultiDimArray(BigArray,DimCount as integer)
134 For n = Lbound(BigArray(),
1) to Ubound(BigArray(),
1)
135 For m =
0 to Dimcount -
1
136 BigArray(n,m) =
""
142 ' Checks if a Field (LocField) is already defined in an Array
143 ' Returns
'True
' or
'False
'
144 Function FieldinArray(LocArray(), MaxIndex as integer, LocField as String) As Boolean
146 For i = Lbound(LocArray()) to MaxIndex
147 If Ucase(LocArray(i)) = Ucase(LocField) Then
156 ' Checks if a Field (LocField) is already defined in an Array
157 ' Returns
'True
' or
'False
'
158 Function FieldinList(LocField, BigList()) As Boolean
160 For i = Lbound(BigList()) to Ubound(BigList())
161 If LocField = BigList(i) Then
170 ' Retrieves the Index of the delivered String
'SearchString
' in
171 ' the Array LocList()
'
172 Function IndexinArray(SearchString as String, LocList()) as Integer
174 For i = Lbound(LocList(),
1) to Ubound(LocList(),
1)
175 If Ucase(LocList(i,
0)) = Ucase(SearchString) Then
184 Sub MultiArrayInListbox(oDialog as Object, ListboxName as String, ValList(), iDim as Integer)
185 Dim oListbox as Object
189 oListbox = oDialog.GetControl(ListboxName)
190 oListbox.RemoveItems(
0, oListbox.GetItemCount)
191 For i =
0 to Ubound(ValList(),
1)
192 If ValList(i)
<> "" Then
193 oListbox.AddItem(ValList(i, iDim-
1), a)
200 ' Searches for a String in a two-dimensional Array by querying all Searchindexex of the second dimension
201 ' and delivers the specific String of the ReturnIndex in the second dimension of the Searchlist()
202 Function StringInMultiArray(SearchList(), SearchString as String, SearchIndex as Integer, ReturnIndex as Integer, Optional MaxIndex as Integer) as String
204 Dim CurFieldString as String
205 If IsMissing(MaxIndex) Then
206 MaxIndex = Ubound(SearchList(),
1)
208 For i = Lbound(SearchList()) to MaxIndex
209 CurFieldString = SearchList(i,SearchIndex)
210 If Ucase(CurFieldString) = Ucase(SearchString) Then
211 StringInMultiArray() = SearchList(i,ReturnIndex)
215 StringInMultiArray() =
""
219 ' Searches for a Value in multidimensial Array by querying all Searchindices of the passed dimension
220 ' and delivers the Index where it is found.
221 Function GetIndexInMultiArray(SearchList(), SearchValue, SearchIndex as Integer) as Integer
223 Dim MaxIndex as Integer
225 MaxIndex = Ubound(SearchList(),
1)
226 For i = Lbound(SearchList()) to MaxIndex
227 CurFieldValue = SearchList(i,SearchIndex)
228 If CurFieldValue = SearchValue Then
229 GetIndexInMultiArray() = i
233 GetIndexInMultiArray() = -
1
237 ' Searches for a Value in multidimensial Array by querying all Searchindices of the passed dimension
238 ' and delivers the Index where the Searchvalue is found as a part string
239 Function GetIndexForPartStringinMultiArray(SearchList(), SearchValue, SearchIndex as Integer) as Integer
241 Dim MaxIndex as Integer
243 MaxIndex = Ubound(SearchList(),
1)
244 For i = Lbound(SearchList()) to MaxIndex
245 CurFieldValue = SearchList(i,SearchIndex)
246 If Instr(CurFieldValue, SearchValue)
> 0 Then
247 GetIndexForPartStringinMultiArray() = i
251 GetIndexForPartStringinMultiArray = -
1
255 Function ArrayfromMultiArray(MultiArray as String, iDim as Integer)
256 Dim MaxIndex as Integer
258 MaxIndex = Ubound(MultiArray())
259 Dim ResultArray(MaxIndex) as String
260 For i =
0 To MaxIndex
261 ResultArray(i) = MultiArray(i,iDim)
263 ArrayfromMultiArray() = ResultArray()
267 ' Replaces the string
"OldReplace
" through the String
"NewReplace
" in the String
268 ' 'BigString
'
269 Function ReplaceString(ByVal Bigstring, NewReplace, OldReplace as String) as String
270 ReplaceString=join(split(BigString,OldReplace),NewReplace)
274 ' Retrieves the second value for a next to
'SearchString
' in
275 ' a two-dimensional string-Array
276 Function FindSecondValue(SearchString as String, TwoDimList() as String ) as String
278 For i =
0 To Ubound(TwoDimList,
1)
279 If Ucase(SearchString) = Ucase(TwoDimList(i,
0)) Then
280 FindSecondValue = TwoDimList(i,
1)
287 ' raises a base to a certain power
288 Function Power(Basis as Double, Exponent as Double) as Double
289 Power = Exp(Exponent*Log(Basis))
293 ' rounds a Real to a given Number of Decimals
294 Function Round(BaseValue as Double, Decimals as Integer) as Double
295 Dim Multiplicator as Long
296 Dim DblValue#, RoundValue#
297 Multiplicator = Power(
10,Decimals)
298 RoundValue = Int(BaseValue * Multiplicator)
299 Round = RoundValue/Multiplicator
303 'Retrieves the mere filename out of a whole path
304 Function FileNameoutofPath(ByVal Path as String, Optional Separator as String) as String
306 Dim SepList() as String
307 If IsMissing(Separator) Then
308 Path = ConvertFromUrl(Path)
309 Separator = GetPathSeparator()
311 SepList() = ArrayoutofString(Path, Separator,i)
312 FileNameoutofPath = SepList(i)
316 Function GetFileNameExtension(ByVal FileName as String)
317 Dim MaxIndex as Integer
318 Dim SepList() as String
319 SepList() = ArrayoutofString(FileName,
".
", MaxIndex)
320 GetFileNameExtension = SepList(MaxIndex)
324 Function GetFileNameWithoutExtension(ByVal FileName as String, Optional Separator as String)
325 Dim MaxIndex as Integer
326 Dim SepList() as String
327 If not IsMissing(Separator) Then
328 FileName = FileNameoutofPath(FileName, Separator)
330 SepList() = ArrayoutofString(FileName,
".
", MaxIndex)
331 GetFileNameWithoutExtension = RTrimStr(FileName,
".
" & SepList(MaxIndex)
335 Function DirectoryNameoutofPath(sPath as String, Separator as String) as String
336 Dim LocFileName as String
337 LocFileName = FileNameoutofPath(sPath, Separator)
338 DirectoryNameoutofPath = RTrimStr(sPath, Separator
& LocFileName)
342 Function CountCharsinString(BigString, LocChar as String, ByVal StartPos as Integer) as Integer
343 Dim LocCount%, LocPos%
346 LocPos = Instr(StartPos,BigString,LocChar)
347 If LocPos
<> 0 Then
348 LocCount = LocCount +
1
351 Loop until LocPos =
0
352 CountCharsInString = LocCount
356 Function BubbleSortList(ByVal SortList(),optional sort2ndValue as Boolean)
357 'This function bubble sorts an array of maximum
2 dimensions.
358 'The default sorting order is the first dimension
359 'Only if sort2ndValue is True the second dimension is the relevant for the sorting order
364 Dim dimensions as Integer
365 Dim sortvalue as Integer
369 On Local Error Goto No2ndDim
370 k = Ubound(SortList(),
2)
372 If Err
<> 0 Then dimensions =
1
374 i = Ubound(SortList(),
1)
375 If ismissing(sort2ndValue) then
383 Select Case dimensions
385 If SortList(t)
> SortList(t+
1) Then
386 DisplayDummy = SortList(t)
387 SortList(t) = SortList(t+
1)
388 SortList(t+
1) = DisplayDummy
391 If SortList(t,sortvalue)
> SortList(t+
1,sortvalue) Then
392 For k =
0 to UBound(SortList(),
2)
393 DisplayDummy = SortList(t,k)
394 SortList(t,k) = SortList(t+
1,k)
395 SortList(t+
1,k) = DisplayDummy
401 BubbleSortList = SortList()
405 Function GetValueoutofList(SearchValue, BigList(), iDim as Integer, Optional ValueIndex)
407 Dim MaxIndex as Integer
408 MaxIndex = Ubound(BigList(),
1)
409 For i =
0 To MaxIndex
410 If BigList(i,
0) = SearchValue Then
411 If Not IsMissing(ValueIndex) Then
414 GetValueOutOfList() = BigList(i,iDim)
420 Function AddListtoList(ByVal FirstArray(), ByVal SecondArray(), Optional StartIndex)
423 Dim MaxIndex as Integer
424 MaxIndex = Ubound(FirstArray()) + Ubound(SecondArray()) +
1
425 If MaxIndex
> -
1 Then
426 Dim ResultArray(MaxIndex)
427 For m =
0 To Ubound(FirstArray())
428 ResultArray(m) = FirstArray(m)
430 For n =
0 To Ubound(SecondArray())
431 ResultArray(m) = SecondArray(n)
434 AddListToList() = ResultArray()
437 AddListToList() = NullArray()
442 Function CheckDouble(DoubleString as String)
443 On Local Error Goto WRONGDATATYPE
444 CheckDouble() = CDbl(DoubleString)
446 If Err
<> 0 Then