Помощ за LibreOffice 7.3
Предоставя набор от методи за манипулиране и трансформиране на едномерни масиви (вектори) и двумерни масиви (матрици). Това включва операции с множества, сортиране, импортиране и експортиране от текстови файлове.
Масиви с повече от две измерения не могат да се използват с методите в тази услуга, с изключение само на метода CountDims, който приема масиви с произволен брой измерения.
Елементите на масивите могат да съдържат стойности от всякакъв тип, включително (под)масиви.
Преди да използвате услугата Array, библиотеката ScriptForge трябва да бъде заредена чрез:
GlobalScope.BasicLibraries.loadLibrary("ScriptForge")
Зареждането на библиотеката ще създаде обекта SF_Array, който може да бъде използван за извикване на методите на услугата Array.
Следващите откъси код показват различни начини за извикване на методите в услугата Array (методът Append е използван като пример):
Dim arr : arr = Array(1, 2, 3)
arr = SF_Array.Append(arr, 4)
Dim arr : arr = Array(1, 2, 3)
Dim svc : svc = SF_Array
arr = svc.Append(arr, 4)
Dim arr : arr = Array(1, 2, 3)
Dim svc : svc = CreateScriptService("Array")
arr = svc.Append(arr, 4)
Because Python has built-in list and tuple support, most of the methods in the Array service are available for Basic scripts only. The only exception is ImportFromCSVFile which is supported in both Basic and Python.
Първият аргумент на повечето методи е разглежданият обект масив. Той винаги се предава по адрес и остава непроменен. Методите като Append, Prepend и т.н. връщат нов обект масив след изпълнението си.
Добавя елементите, изброени като аргументи, в края на входния масив.
svc.Append(array_1d: any[0..*], arg0: any, [arg1: any] ...): any[0..*]
array_1d: The pre-existing array, may be empty.
arg0, arg1, ...: Items that will be appended to array_1d.
Dim a As Variant
a = SF_Array.Append(Array(1, 2, 3), 4, 5)
' (1, 2, 3, 4, 5)
Добавя нова колона към дясната страна на двумерен масив. Полученият масив има същите долни граници като началния двумерен масив.
svc.AppendColumn(array_2d: any[0..*, 0..*], column: any[0..*]): any[0..*, 0..*]
array_2d: The pre-existing array, may be empty. If that array has only one dimension, it is considered as the first column of the resulting two-dimensional array.
column: A 1-dimensional array with as many items as there are rows in array_2d.
Dim a As Variant, b As variant
a = SF_Array.AppendColumn(Array(1, 2, 3), Array(4, 5, 6))
' ((1, 4), (2, 5), (3, 6))
b = SF_Array.AppendColumn(a, Array(7, 8, 9))
' ((1, 4, 7), (2, 5, 8), (3, 6, 9))
c = SF_Array.AppendColumn(Array(), Array(1, 2, 3))
' ∀ i ∈ {0 ≤ i ≤ 2} : b(0, i) ≡ i
Добавя нов ред към долната страна на двумерен масив. Полученият масив има същите долни граници като началния двумерен масив.
svc.AppendRow(array_2d: any[0..*, 0..*], row: any[0..*]): any[0..*, 0..*])
array_2d: The pre-existing array, may be empty. If that array has 1 dimension, it is considered as the first row of the resulting 2 dimension array.
row: A 1-dimensional array with as many items as there are columns in array_2d.
Dim a As Variant, b As variant
a = SF_Array.AppendRow(Array(1, 2, 3), Array(4, 5, 6))
' ((1, 2, 3), (4, 5, 6))
b = SF_Array..AppendRow(Array(), Array(1, 2, 3))
' ∀ i ∈ {0 ≤ i ≤ 2} : b(i, 0) ≡ i
Проверява дали едномерен масив съдържа определено число, текст или дата. Сравняването на текст може да бъде или да не бъде чувствително към регистъра.
Сортираните входни масиви трябва да бъдат запълнени хомогенно, тоест всички елементи трябва да са скалари от един и същ тип (елементи със стойност Empty и Null са забранени).
Резултатът от метода е непредсказуем, когато масивът е обявен като сортиран, но в действителност не е такъв.
Ако масивът е сортиран, се извършва двоично търсене, в противен случай той просто се обхожда от началото до края и елементите Empty и Null се игнорират.
svc.Contains(array_1d: any[0..*], tofind: any, casesensitive: bool = False, sortorder: str = ""): bool
array_1d: The array to scan.
tofind: A number, a date or a string to find.
casesensitive: Only for string comparisons (Default = False).
sortorder: It can be either "ASC", "DESC" or "" (not sorted). The default value is "".
Dim a As Variant
a = SF_Array.Contains(Array("A","B","c","D"), "C", SortOrder := "ASC") ' True
SF_Array.Contains(Array("A","B","c","D"), "C", CaseSensitive := True) ' False
Съхранява съдържанието на масив с две колони в обект от тип ScriptForge.Dictionary.
Ключът се извлича от първата колона, а елементът – от втората.
svc.ConvertToDictionary(array_2d: any[0..*, 0..1]): obj
array_2d: Data to be converted into a ScriptForge.Dictionary object.
The first column must contain exclusively strings with a length greater than zero, in any order. These values will be used as labels in the dictionary.
The second column contains the data that will be associated to the corresponding label in the dictionary.
Dim a As Variant, b As Variant
a = SF_Array.AppendColumn(Array("a", "b", "c"), Array(1, 2, 3))
b = SF_Array.ConvertToDictionary(a)
MsgBox b.Item("c") ' 3
Creates a copy of a 1D or 2D array.
svc.Copy(array_nd: any[0..*]): any[0..*]
svc.Copy(array_nd: any[0..*, 0..*]): any[0..*, 0..*]
array_nd: The 1D or 2D array to be copied.
A simple assignment of an Array object will copy its reference instead of creating a copy of the object's contents. See the example below:
Dim a as Variant, b as Variant
a = Array(1, 2, 3)
' The assignment below is made by reference
b = a
' Hence changing values in "b" will also change "a"
b(0) = 10
MsgBox a(0) ' 10
By using the Copy method, a copy of the whole Array object is made. In the example below, a and b are different objects and changing values in b will not affect values in a.
Dim a as Variant, b as Variant
a = Array(1, 2, 3)
' Creates a copy of "a" using the "Copy" method
b = SF_Array.Copy(a)
b(0) = 10
MsgBox a(0) ' 1
Count the number of dimensions of an array. The result can be greater than two.
If the argument is not an array, returns -1
If the array is not initialized, returns 0.
svc.CountDims(array_nd: any): int
array_nd: The array to examine.
Dim a(1 To 10, -3 To 12, 5)
MsgBox SF_Array.CountDims(a) ' 3
Конструира множество във вид на индексиран от нула масив, като прилага операцията разлика върху двата входни масива. Резултатът включва елементите, които присъстват в първия масив, но не и във втория.
Резултатният масив е сортиран във възходящ ред.
Двата входни масива трябва да са попълнени хомогенно, елементите им трябва да са скалари от един и същ тип. Елементи със стойност Empty и Null са забранени.
Сравняването на текст може да бъде чувствително или нечувствително към регистъра.
svc.Difference(array1_1d: any[0..*], array2_1d: any[0..*], casesensitive: bool = False): any[0..*]
array1_1d: A 1-dimensional reference array, whose items are examined for removal.
array2_1d: A 1-dimensional array, whose items are subtracted from the first input array.
casesensitive: This argument is only applicable if the arrays are populated with strings (Default = False).
Dim a As Variant
a = SF_Array.Difference(Array("A", "C", "A", "b", "B"), Array("C", "Z", "b"), True)
' ("A", "B")
Записва всички елементи на масива последователно в текстов файл. Ако файлът вече съществува, той ще бъде заменен без предупреждение.
svc.ExportToTextFile(array_1d: any[0..*], filename: str, [encoding: str]): bool
array_1d: The array to export. It must contain only strings.
filename: The name of the text file where the data will be written to. The name must be expressed according to the current FileNaming property of the SF_FileSystem service.
encoding: The character set that should be used. Use one of the names listed in IANA character sets. Note that LibreOffice may not implement all existing character sets (Default is "UTF-8").
SF_Array.ExportToTextFile(Array("A","B","C","D"), "C:\Temp\A short file.txt")
Извлича указана колона от двуизмерен масив като нов масив.
Долната и горната му граница, LBound и UBound, са идентични на тези на първото измерение на входния масив.
svc.ExtractColumn(array_2d: any[0..*, 0..*], columnindex: int): any[0..*, 0..*]
array_2d: The array from which to extract.
columnindex: The column number to extract - must be in the interval [LBound, UBound].
'Създава матрица 3x3: |1, 2, 3|
' |4, 5, 6|
' |7, 8, 9|
Dim mat as Variant, col as Variant
mat = SF_Array.AppendRow(Array(), Array(1, 2, 3))
mat = SF_Array.AppendRow(mat, Array(4, 5, 6))
mat = SF_Array.AppendRow(mat, Array(7, 8, 9))
'Извлича третата колона: |3, 6, 9|
col = SF_Array.ExtractColumn(mat, 2)
Извлича указан ред от двуизмерен масив като нов масив.
Долната и горната му граница, LBound и UBound, са идентични на тези на второто измерение на входния масив.
svc.ExtractRow(array_2d: any[0..*, 0..*], rowindex: int): any[0..*, 0..*]
array_2d: The array from which to extract.
rowindex: The row number to extract - must be in the interval [LBound, UBound].
'Създава матрица 3x3: |1, 2, 3|
' |4, 5, 6|
' |7, 8, 9|
Dim mat as Variant, row as Variant
mat = SF_Array.AppendRow(Array(), Array(1, 2, 3))
mat = SF_Array.AppendRow(mat, Array(4, 5, 6))
mat = SF_Array.AppendRow(mat, Array(7, 8, 9))
'Извлича първия ред: |1, 2, 3|
row = SF_Array.ExtractRow(mat, 0)
Подрежда всички единични елементи на масив и всички елементи на подмасивите му в един нов масив без подмасиви. Празните подмасиви се игнорират, а подмасивите с повече от едно измерение не се изравняват.
svc.Flatten(array_1d: any[0..*]): any[0..*]
array_1d: The pre-existing array, may be empty.
Dim a As Variant
a = SF_Array.Flatten(Array(Array(1, 2, 3), 4, 5))
' (1, 2, 3, 4, 5)
Можете да използвате метода Flatten заедно с други методи, като Append или Prepend, за да конкатенирате съвкупност от едномерни масиви в един едномерен масив.
Следва пример как методите Flatten и Append могат да се комбинират за конкатениране на три масива.
'Създава три масива за този пример
Dim a as Variant, b as Variant, c as Variant
a = Array(1, 2, 3)
b = Array(4, 5)
c = Array(6, 7, 8, 9)
'Конкатенира трите масива в един едномерен масив
Dim arr as Variant
arr = SF_Array.Flatten(SF_Array.Append(a, b, c))
'(1, 2, 3, 4, 5, 6, 7, 8, 9)
Импортира данните от файл със стойности, разделени със запетая (CSV). Запетаята може да бъде заменена с произволен друг знак.
Приложимият формат CSV е описан в документа IETF Common Format and MIME Type for CSV Files.
Всеки ред във файла съдържа по един пълен запис (не се разрешава разделяне на редове на части).
Последователности от рода на \n, \t, ... остават непроменени. За тяхната обработка използвайте метода SF_String.Unescape().
Методът връща двуизмерен масив, чиито редове съответстват на записите, прочетени от файла, а колоните – на полета от записите. Не се проверява дали типовете на полетата са съгласувани в рамките на колоните. Прави се опит за разпознаване на числа и дати.
Ако някой ред съдържа повече или по-малко полета от първия ред във файла, ще възникне изключение. Празните редове обаче просто се игнорират. Ако размерът на файла надхвърля ограничението за брой на елементите (вижте в кода), ще бъде издадено предупреждение и масивът ще бъде съкратен.
svc.ImportFromCSVFile(filename: str, delimiter: str = ',', dateformat: str = ''): any[0..*]
filename: The name of the text file containing the data. The name must be expressed according to the current FileNaming property of the SF_FileSystem service.
delimiter: A single character, usually, a comma, a semicolon or a TAB character (Default = ",").
dateformat: A special mechanism handles dates when dateformat is either "YYYY-MM-DD", "DD-MM-YYYY" or "MM-DD-YYYY". The dash (-) may be replaced by a dot (.), a slash (/) or a space. Other date formats will be ignored. Dates defaulting to an empty string "" are considered as normal text.
Consider the CSV file "myFile.csv" with the following contents:
Name,DateOfBirth,Address,City
Anna,2002/03/31,"Rue de l'église, 21",Toulouse
Fred,1998/05/04,"Rue Albert Einstein, 113A",Carcassonne
The examples below in Basic and Python read the contents of the CSV file into an Array object.
Dim arr As Variant
arr = SF_Array.ImportFromCSVFile("C:\Temp\myFile.csv", DateFormat := "YYYY/MM/DD")
MsgBox arr(0, 3) ' City
MsgBox arr(1, 2) ' Rue de l'église, 21
MsgBox arr(1, 3) ' Toulouse
from scriptforge import CreateScriptService
svc = CreateScriptService("Array")
bas = CreateScriptService("Basic")
arr = svc.ImportFromCSVFile(r"C:\Temp\myFile.csv", dateformat = "YYYY/MM/DD")
bas.MsgBox(arr[0][3]) # City
bas.MsgBox(arr[1][2]) # Rue de l'église, 21
bas.MsgBox(arr[1][3]) # Toulouse
Претърсва едномерен масив за число, низ или дата. Сравняването на текст може да бъде или да не бъде чувствително към регистъра.
Ако масивът е сортиран, той трябва да е запълнен хомогенно, тоест всички елементи трябва да са скалари от един и същ тип (елементи със стойност Empty и Null са забранени).
Резултатът от метода е непредсказуем, когато масивът е обявен като сортиран, но в действителност не е такъв.
Ако масивът е сортиран, се извършва двоично търсене. В противен случай той просто се обхожда от началото до края и елементите Empty и Null се игнорират.
Ако търсенето е неуспешно, методът връща LBound(input array) - 1.
svc.IndexOf(array_1d: any[0..*], tofind: any, casesensitive: bool = False, sortorder: str = ''): int
array_1d: The array to scan.
tofind: A number, a date or a string to find.
casesensitive: Only for string comparisons (Default = False).
sortorder: It can be either "ASC", "DESC" or "" (not sorted). The default value is "".
MsgBox SF_Array.IndexOf(Array("A","B","c","D"), "C", SortOrder := "ASC") ' 2
MsgBox SF_Array.IndexOf(Array("A","B","c","D"), "C", CaseSensitive := True) ' -1
Вмъква преди даден индекс на входния масив елементите, изброени като аргументи.
Аргументите се вмъкват без проверка. Всеки от тях може да бъде или скалар от произволен тип, или подмасив.
svc.Insert(array_1d: any[0..*], before: int, arg0: any, [arg1: any] ...): any[0..*]
array_1d: The pre-existing array, may be empty.
before: The index before which to insert; must be in the interval [LBound, UBound + 1].
arg0, arg1, ...: Items that will be inserted into array_1d.
Dim a As Variant
a = SF_Array.Insert(Array(1, 2, 3), 2, "a", "b")
' (1, 2, "a", "b", 3)
Inserts into a sorted array a new item on its place.
The array must be filled homogeneously, meaning that all items must be scalars of the same type.
Empty and Null items are forbidden.
svc.InsertSorted(array_1d: any[0..*], item: any, sortorder: str = 'ASC', casesensitive: bool = False): any[0..*]
array_1d: The array into which the value will be inserted.
item: The scalar value to insert, of the same type as the existing array items.
sortorder: It can be either "ASC" (default) or "DESC".
casesensitive: Only for string comparisons (Default = False).
Dim a As Variant
a = SF_Array.InsertSorted(Array("A", "C", "a", "b"), "B", CaseSensitive := True)
' ("A", "B", "C", "a", "b")
Конструира множество във вид на индексиран от нула масив, като прилага операцията сечение върху двата входни масива. Резултатът включва елементите, които присъстват и в двата масива.
Резултатният масив е сортиран във възходящ ред.
Двата входни масива трябва да са попълнени хомогенно, с други думи, елементите им трябва да са скалари от един и същ тип. Елементи със стойност Empty и Null са забранени.
Сравняването на текст може да бъде чувствително или нечувствително към регистъра.
svc.Intersection(array1_1d: any[0..*], array2_1d: any[0..*], casesensitive: bool = False): any[0..*]
array1_1d: The first input array.
array2_1d: The second input array.
casesensitive: Applies to arrays populated with text items (Default = False).
Dim a As Variant
a = SF_Array.Intersection(Array("A", "C", "A", "b", "B"), Array("C", "Z", "b"), True)
' ("C", "b")
Обединява двумерен масив с два разделителя, един за колоните и един за редовете.
svc.Join2D(array_2d: any [0..*, 0..*], [columndelimiter: str], [rowdelimiter: str], [quote: str]): str
array_2d: Each item must be either text, a number, a date or a boolean.
Dates are transformed into the YYYY-MM-DD hh:mm:ss format.
Invalid items are replaced by a zero-length string.
columndelimiter: Delimits each column (default = Tab/Chr(9)).
rowdelimiter: Delimits each row (default = LineFeed/Chr(10))
quote: If True, protect strings with double quotes. The default is False.
' arr = | 1, 2, "A", [2020-02-29], 51, 2, "A", [2020-02-29], 5 |
' | 6, 7, "this is a string", 9, 106, 7, "this is a string", 9, 10 |
Dim arr as Variant : arr = Array()
arr = SF_Array.AppendRow(arr, Array(1, 2, "A", [2020-02-29], 51, 2, "A", [2020-02-29], 5))
arr = SF_Array.AppendRow(arr, Array(6, 7, "this is a string", 9, 106, 7, "this is a string", 9, 10))
Dim arrText as String
arrText = SF_Array.Join2D(arr, ",", "/", False)
' 1,2,A,,51,2,A,,5/6,7,this is a string,9,106,7,this is a string,9,10
Добавя в началото на входния масив елементите, изброени като аргументи.
svc.Prepend(array_1d: any[0..*], arg0: any, [arg1: any] ...): any[0..*]
array_1d: The pre-existing array, may be empty.
arg0, arg1, ...: A list of items to prepend to array_1d.
Dim a As Variant
a = SF_Array.Prepend(Array(1, 2, 3), 4, 5)
' (4, 5, 1, 2, 3)
Добавя нова колона към лявата страна на двумерен масив. Полученият масив има същите долни граници като началния двумерен масив.
svc.PrependColumn(array_2d: any[0..*, 0..*], column: any[0..*]): any[0..*, 0..*]
array_2d: The pre-existing array, may be empty. If that array has 1 dimension, it is considered as the last column of the resulting 2 dimension array.
column: A 1-dimensional array with as many items as there are rows in array_2d.
Dim a As Variant, b As variant
a = SF_Array.PrependColumn(Array(1, 2, 3), Array(4, 5, 6))
' ((4, 1), (5, 2), (6, 3))
b = SF_Array.PrependColumn(Array(), Array(1, 2, 3))
' ∀ i ∈ {0 ≤ i ≤ 2} : b(0, i) ≡ i
Prepend a new row at the beginning of a 2-dimensional array. The resulting array has the same lower boundaries as the initial 2-dimensional array.
svc.PrependRow(array_2d: any[0..*, 0..*], row: any[0..*]): any[0..*, 0..*]
array_2d: The pre-existing array, may be empty. If that array has 1 dimension, it is considered as the last row of the resulting 2-dimensional array.
row: A 1-dimensional array containing as many items as there are columns in array_2d.
Dim a As Variant, b As variant
a = SF_Array.PrependRow(Array(1, 2, 3), Array(4, 5, 6))
' ((4, 5, 6), (1, 2, 3))
b = SF_Array.PrependRow(Array(), Array(1, 2, 3))
' ∀ i ∈ {0 ≤ i ≤ 2} : b(i, 0) ≡ i
Инициализира нов индексиран от нула масив с числови стойности.
svc.RangeInit(from: num, upto: num, [bystep: num]): num[0..*]
from: Value of the first item.
upto: The last item should not exceed UpTo.
bystep: The difference between two successive items (Default = 1).
Dim a As Variant
a = SF_Array.RangeInit(10, 1, -1)
' (10, 9, 8, 7, 6, 5, 4, 3, 2, 1)
Връща обърнатия едномерен входен масив.
svc.Reverse(array_1d: any[0..*]): any[0..*]
array_1d: The array to reverse.
Dim a As Variant
a = SF_Array.Reverse(Array("a", 2, 3, 4))
' (4, 3, 2, "a")
Returns a random permutation of a one-dimensional array.
svc.Shuffle(array_1d: any[0..*]): any[0..*]
array_1d: The array to shuffle.
Dim a As Variant
a = SF_Array.Shuffle(Array(1, 2, 3, 4))
' Array "a" is now in random order, f.i. (2, 3, 1, 4)
Returns a subset of a one-dimensional array.
svc.Slice(array_1d: any[0..*], from: int, [upto: int]): any[0..*]
array_1d: The array to slice.
from: The lower index in array_1d of the subarray to extract (from included)
upto: The upper index in array_1d of the subarray to extract (upto included). The default value is the upper bound of array_1d. If upto < from then the returned array is empty.
Dim a As Variant
a = SF_Array.Slice(Array(1, 2, 3, 4, 5), 1, 3) ' (2, 3, 4)
Сортира едномерен масив във възходящ или низходящ ред. Сравняването на текст може да бъде чувствително или нечувствително към регистъра.
Масивът трябва да бъде запълнен хомогенно, тоест всички елементи трябва да бъдат скалари от един и същ тип.
Не се допускат елементи Empty и Null. По конвенция Empty < Null < всяка друга скаларна стойност.
svc.Sort(array_1d: any[0..*], sortorder: str, casesensitive: bool = False): any[0..*]
array_1d: The array to sort.
sortorder: It can be either "ASC" (default) or "DESC".
casesensitive: Only for string comparisons (Default = False).
Dim a As Variant
a = SF_Array.Sort(Array("a", "A", "b", "B", "C"), CaseSensitive := True)
' ("A", "B", "C", "a", "b")
Връща пермутация на колоните на двумерен масив, сортирани според стойностите на даден ред.
Редът трябва да бъде запълнен хомогенно, тоест всички елементи трябва да бъдат скалари от един и същ тип.
Не се допускат елементи Empty и Null. По конвенция Empty < Null < всяка друга скаларна стойност.
svc.SortColumns(array_2d: any[0..*, 0..*], rowindex: int, sortorder: str, casesensitive: bool = False): any[0..*, 0..*]
array_2d: The 2-dimensional array to sort.
rowindex: The index of the row that will be used as reference to sort the columns.
sortorder: It can be either "ASC" (default) or "DESC".
casesensitive: Only for string comparisons (Default = False).
' arr = | 5, 7, 3 |
' | 1, 9, 5 |
' | 6, 1, 8 |
Dim arr as Variant : arr = Array(5, 7, 3)
arr = SF_Array.AppendRow(arr, Array(1, 9, 5))
arr = SF_Array.AppendRow(arr, Array(6, 1, 8))
arr = SF_Array.SortColumns(arr, 2, "ASC")
' arr = | 7, 5, 3 |
' | 9, 1, 5 |
' | 1, 6, 8 |
Връща пермутация на редовете на двумерен масив, сортирани според стойностите на дадена колона.
Колоната трябва да бъде запълнена хомогенно, тоест всички елементи трябва да бъдат скалари от един и същ тип.
Не се допускат елементи Empty и Null. По конвенция Empty < Null < всяка друга скаларна стойност.
svc.SortRows(array_2d: any[0..*, 0..*], columnindex: int, sortorder: str, casesensitive: bool = False): any[0..*, 0..*]
array_2d: The array to sort.
columnindex: The index of the column that will be used as reference to sort the rows.
sortorder: It can be either "ASC" (default) or "DESC".
casesensitive: Only for string comparisons (Default = False).
' arr = | 5, 7, 3 |
' | 1, 9, 5 |
' | 6, 1, 8 |
Dim arr as Variant : arr = Array(5, 7, 3)
arr = SF_Array.AppendRow(arr, Array(1, 9, 5))
arr = SF_Array.AppendRow(arr, Array(6, 1, 8))
arr = SF_Array.SortRows(arr, 0, "ASC")
' arr = | 1, 9, 5 |
' | 5, 7, 3 |
' | 6, 1, 8 |
Swaps rows and columns in a two-dimensional array.
svc.Transpose(array_2d: any[0..*, 0..*]): any[0..*, 0..*]
array_2d: The 2-dimensional array to transpose.
' arr1 = | 1, 2 |
' | 3, 4 |
' | 5, 6 |
arr1 = Array(1, 2)
arr1 = SF_Array.AppendRow(arr1, Array(3, 4))
arr1 = SF_Array.AppendRow(arr1, Array(5, 6))
arr2 = SF_Array.Transpose(arr1)
' arr2 = | 1, 3, 5 |
' | 2, 4, 6 |
MsgBox arr2(0, 2) ' 5
Премахва от едномерен масив всички елементи Null, Empty и с нулева дължина.
Елементите низове се подрязват с функцията на LibreOffice Basic Trim().
svc.TrimArray(array_1d: any[0..*]): any[0..*]
array_1d: The array to trim.
Dim a As Variant
a = SF_Array.TrimArray(Array("A", "B", Null, " D "))
' ("A", "B", "D")
Builds a set, as a zero-based array, by applying the union operator on the two input arrays. Resulting items originate from any of both arrays.
The resulting array is sorted in ascending order.
Both input arrays must be filled homogeneously, their items must be scalars of the same type. Empty and Null items are forbidden.
Text comparison can be case sensitive or not.
svc.Union(array1_1d: any[0..*], array2_1d: any[0..*], casesensitive: bool = False): any[0..*]
array1_1d: The first input array.
array2_1d: The second input array.
casesensitive: Applicable only if the arrays are populated with strings (Default = False).
Dim a As Variant
a = SF_Array.Union(Array("A", "C", "A", "b", "B"), Array("C", "Z", "b"), True)
' ("A", "B", "C", "Z", "b")
Конструира множество от уникални стойности на базата на входния масив.
Входният масив трябва да е запълнен хомогенно, тоест елементите му трябва да са скалари от един и същ тип. Елементи Empty и Null са забранени.
Сравняването на текстове може да бъде чувствително или нечувствително към регистъра.
svc.Unique(array_1d: any[0..*], casesensitive: bool = False): any[0..*]
array_1d: The input array.
casesensitive: Applicable only if the array is populated with strings (Default = False).
Dim a As Variant
a = SF_Array.Unique(Array("A", "C", "A", "b", "B"), CaseSensitive := True)
' ("A", "B", "C", "b")