Aide LibreOffice 7.3
Fournit une collection de méthodes pour manipuler et transformer des matrices d'une dimension (vecteurs) et des matrices de deux dimensions (matrices). Cela inclut les opérations d'ensemble, le tri, l'import et l'export à partir de fichiers texte.
Les matrices avec plus de deux dimensions ne peuvent pas être utilisées avec les méthodes de ce service, la seule exception étant la méthode CountDims qui accepte les matrices avec un nombre quelconque de dimensions.
Les éléments de matrice peuvent contenir n'importe quel type de valeur, y compris des (sous) matrices.
Avant de pouvoir utiliser le service Array, la bibliothèque ScriptForge doit être chargée en utilisant :
GlobalScope.BasicLibraries.loadLibrary("ScriptForge")
Charger la bibliothèque créera l'objet SF_Array qui peut être utilisé pour appeler les méthode dans le service Array.
Les extraits de code suivants montrent les différentes façons d'appeler des méthodes dans le service Array (la méthode Append est utilisée comme exemple) :
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.
Le premier argument de la plupart des méthodes est l'objet matrice à prendre en compte. Il est toujours passé par référence et laissé inchangé. Les méthodes telles que Append, Prepend, etc. renvoient un nouvel objet matrice après leur exécution.
Ajoute les éléments répertoriés comme arguments à la fin de la matrice d'entrée.
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)
Ajoute une nouvelle colonne sur le côté droit d'une matrice à deux dimensions. La matrice résultante a les mêmes limites inférieures que la matrice bidimensionnelle initiale.
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
Ajoutez une nouvelle ligne au bas d'une matrice à deux dimensions. La matrice résultante a les mêmes limites inférieures que la matrice initiale à deux dimensions.
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
Vérifier si un tableau à une dimension contient un certain nombre, du texte ou une date. La comparaison de texte peut être sensible à la casse ou non.
Les matrices d'entrée triées doivent être remplies de manière homogène, ce qui signifie que tous les éléments doivent être des scalaires du même type (les éléments Empty et Null sont interdits).
Le résultat de la méthode est imprévisible lorsque la matrice est annoncée comme triée et ne l'est pas en réalité.
Une recherche binaire est effectuée lorsque la matrice est triée, sinon, elle est simplement parcourue de haut en bas et les éléments Empty et Null sont ignorés.
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
Stocker le contenu d'une matrice de deux colonnes dans un objet ScriptForge.Dictionary . Les clés seront extraites de la première colonne et les éléments de la seconde.
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
Construisez un ensemble, dont la matrice est basée sur 0, en utilisant l'opérateur de différence sur les deux matrices d'entrée. Les éléments résultants viendront du premier tableau et non du second.
La matrice résultante est triée par ordre croissant.
Les deux matrices d'entrée doivent être remplies avec homogénéité, leurs éléments doivent être des scalaires de même type. Les valeurs Empty et Null ne sont pas permises.
La comparaison de texte peut être sensible à la casse ou non.
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")
Écrivez tous les éléments du tableau de manière séquentielle dans un fichier texte. Si le fichier existe déjà, il sera écrasé sans avertissement.
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")
Extraire d'une matrice à deux dimensions une colonne spécifique en tant que nouvelle matrice.
Ses limites inférieures LBound et supérieures UBound sont identiques à celles de la première dimension de la matrice d'entrée.
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].
'Crée une matrice 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))
'Extrait la troisième colonne : |3, 6, 9|
col = SF_Array.ExtractColumn(mat, 2)
Extraire d'une matrice à deux dimensions une ligne spécifique en tant que nouvelle matrice.
Ses limites inférieures LBound et supérieures UBound sont identiques à celles de la deuxième dimension de la matrice d'entrée.
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].
'Crée une matrice 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))
'Extrait la première ligne : |1, 2, 3|
row = SF_Array.ExtractRow(mat, 0)
Empilez tous les éléments individuels d'une matrice et tous les éléments de ses sous-matrices dans une nouvelle matrice sans sous-matrice. Les sous-matrices vides sont ignorées et les sous-matrices avec un nombre de dimensions supérieur à un ne sont pas aplaties.
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)
Vous pouvez utiliser la méthode Flatten en même temps que d'autres méthodes telles que Append ou Prepend pour concaténer un ensemble de matrices 1D en une seule matrice 1D.
Vous trouverez ci-après un exemple de comment les méthodes Flatten et Append peuvent être combinées pour concaténer trois matrices.
'Crée trois matrices pour cet exemple
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)
'Concatène les trois matrices en une seule matrice 1D
Dim arr as Variant
arr = SF_Array.Flatten(SF_Array.Append(a, b, c))
'(1, 2, 3, 4, 5, 6, 7, 8, 9)
Importez les données contenues dans un fichier dont les valeurs sont séparées par des virgules (CSV). Les virgules peuvent être remplacées par n'importe quel caractère.
Le format CSV applicable est décrit dans IETF Common Format and MIME Type for CSV Files.
Chaque ligne du fichier contient un enregistrement complet (séparer les lignes n'est pas autorisé).
Cependant, des séquences comme \n, \t, ... sont laissées inchangées. Utilisez la méthode SF_String.Unescape() pour les gérer.
La méthode renvoie une matrice à deux dimensions dont les lignes correspondent à un enregistrement unique lu dans un fichier dont les colonnes correspondent à un champ de l'enregistrement. Aucune vérification n'est faite quant à la cohérence des types de champs à travers les colonnes. Une meilleure estimation sera faite pour identifier les types numériques et de date.
Si une ligne contient plus ou moins de champs que la première ligne du fichier, une exception est levée. Cependant les lignes vides sont simplement ignorées. Si la taille du fichier excède le nombre de la limite d'éléments (voir à l'intérieur du code), un avertissement est levé et la matrice est tronquée.
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
Rechercher dans une matrice à une dimension un nombre, une chaîne ou une date. La comparaison de texte peut être sensible ou non à la casse.
Si la matrice est triée, elle doit être remplie de manière homogène, ce qui signifie que tous les éléments doivent être des scalaires du même type (les éléments Empty et Null sont interdits).
Le résultat de la méthode est imprévisible lorsque la matrice est annoncée comme triée et ne l'est pas en réalité.
Une recherche binaire est effectuée sur des matrices triées. Sinon, les matrices sont simplement analysées de haut en bas et les éléments Empty et Null sont ignorés.
La méthode renvoie LBound(input array) - 1 si la recherche n'a pas abouti.
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
Insérez avant un index donné de la matrice d'entrée, les éléments répertoriés comme arguments.
Les arguments sont insérés à l'aveugle. Chacun d'eux peut être soit un scalaire de n'importe quel type, soit une sous-matrice.
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")
Construire un ensemble, en tant que matrice de base zéro, en appliquant l'opérateur d'ensemble d'intersection sur les deux matrices d'entrée. Les éléments résultants sont contenus dans les deux matrices.
La matrice résultante est triée par ordre croissant.
Les deux matrices d'entrée doivent être remplies de manière homogène, c'est-à-dire que tous les éléments doivent être des scalaires du même type. Les éléments Empty et Null sont interdits.
La comparaison de texte peut être sensible ou non à la casse.
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")
Joindre une matrice à deux dimensions avec deux délimiteurs, un pour les colonnes, un pour les lignes.
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
Ajouter au début de la matrice d'entrée les éléments répertoriés comme arguments.
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)
Ajouter au côté gauche d'une matrice à deux dimensions une nouvelle colonne. La matrice résultante a les mêmes limites inférieures que la matrice initiale à deux dimensions.
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
Initialiser un nouveau tableau de base zéro avec des valeurs numériques.
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)
Return the reversed one dimension input array.
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)
Sort a one dimension array in ascending or descending order. Text comparisons can be case-sensitive or not.
The array must be filled homogeneously, which means that items must be scalars of the same type.
Empty and Null items are allowed. Conventionally Empty < Null < any other scalar value.
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")
Return a permutation of the columns of a two dimension array, sorted on the values of a given row.
The row must be filled homogeneously, which means that all items must be scalars of the same type.
Empty and Null items are allowed. Conventionally Empty < Null < any other scalar value.
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 |
Return a permutation of the rows of a two dimension array, sorted on the values of a given column.
The column must be filled homogeneously, therefore all items must be scalars of the same type.
Empty and Null items are allowed. Conventionally Empty < Null < any other scalar value.
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
Remove from a one dimension array all Null, Empty and zero-length entries.
String items are trimmed with LibreOffice Basic Trim() function.
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")
Build a set of unique values derived from the input array.
The input array must be filled homogeneously, its items must be scalars of the same type. Empty and Null items are forbidden.
Text comparison can be case sensitive or not.
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")