Servizio ScriptForge.Array

Fornisce una raccolta di metodi per manipolare e trasformare matrici a una dimensione (vettori) e a due dimensioni (matrici). Questi comprendono: operazioni di inserimento, ordinamento, importazione da ed esportazione in file di testo.

Le matrici con più di due dimensioni non possono essere usate con i metodi di questo servizio, con l'unica eccezione del metodo CountDims che accetta matrici con qualsiasi numero di dimensioni.

Gli elementi delle matrici possono contenere qualsiasi tipo di valore, comprese matrici nidificate.

Invocare il servizio

Prima di usare il servizio Array è necessario caricare le librerie ScriptForge usando:


    GlobalScope.BasicLibraries.loadLibrary("ScriptForge")
  

Il caricamento della libreria creerà l'oggetto SF_Array che può essere usato per chiamare i metodi del servizio Array.

I seguenti frammenti di codice mostrano diversi modi per richiamare i metodi del servizio Array (il metodo Append è usato come esempio):


    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)
  
warning

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.


List of Methods in the Array Service

Append
AppendColumn
AppendRow
Contains
ConvertToDictionary
Copy
CountDims
Difference
ExportToTextFile
ExtractColumn
ExtractRow

Flatten
ImportFromCSVFile
IndexOf
Insert
InsertSorted
Intersection
Join2D
Prepend
PrependColumn
PrependRow
RangeInit

Reverse
Shuffle
Slice
Sort
SortColumns
SortRows
Transpose
TrimArray
Union
Unique


tip

Il primo argomento della maggior parte dei metodi è l'oggetto matrice da considerare. Viene passato sempre per riferimento e rimane inalterato. I metodi come Append, Prepend, ecc. dopo la loro esecuzione restituiscono una nuova matrice.


Append

Aggiunge gli elementi elencati negli argomenti alla fine della matrice di partenza.

Sintassi:

svc.Append(array_1d: any[0..*], arg0: any, [arg1: any] ...): any[0..*]

Parametri:

array_1d: The pre-existing array, may be empty.

arg0, arg1, ...: Items that will be appended to array_1d.

Esempio:


    Dim a As Variant
    a = SF_Array.Append(Array(1, 2, 3), 4, 5)
        ' (1, 2, 3, 4, 5)
  

AppendColumn

Aggiunge una nuova colonna alla destra di una matrice bidimensionale. La matrice che ne risulta ha gli stessi limiti inferiori della matrice bidimensionale iniziale.

Sintassi:

svc.AppendColumn(array_2d: any[0..*, 0..*], column: any[0..*]): any[0..*, 0..*]

Parametri:

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.

Esempio:


    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
  

AppendRow

Aggiunge un nuova riga in fondo a una matrice bidimensionale. La matrice che ne risulta ha gli stessi limiti inferiori della matrice bidimensionale iniziale.

Sintassi:

svc.AppendRow(array_2d: any[0..*, 0..*], row: any[0..*]): any[0..*, 0..*])

Parametri:

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.

Esempio:


    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
  

Contains

Controlla se una matrice unidimensionale contiene un determinato numero, testo o data. La comparazione del testo può essere soggetta a distinzione tra maiuscole e minuscole oppure no.
Le matrici ordinate di partenza devono essere riempite in modo omogeneo, ciò significa che tutti gli elementi devono essere scalari dello stesso tipo (i valori Empty e Null sono vietati).
Il risultato del metodo non è prevedibile se una matrice viene passata come ordinata, ma in realtà non lo è.
Se la matrice è ordinata viene effettuata una ricerca di tipo binario, altrimenti viene semplicemente controllata da cima a fondo ed i valori Empty e Null vengono ignorati.

Sintassi:

svc.Contains(array_1d: any[0..*], tofind: any, casesensitive: bool = False, sortorder: str = ""): bool

Parametri:

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 "".

Esempio:


    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
  

ConvertToDictionary

Memorizza il contenuto di una matrice bidimensionale in un oggetto ScriptForge.Dictionary.
La chiave sarà estratta dalla prima colonna e l'elemento dalla seconda.

Sintassi:

svc.ConvertToDictionary(array_2d: any[0..*, 0..1]): obj

Parametri:

array_2d: Data to be converted into a ScriptForge.Dictionary object.

Esempio:


    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
  

Copy

Creates a copy of a 1D or 2D array.

Sintassi:

svc.Copy(array_nd: any[0..*]): any[0..*]

svc.Copy(array_nd: any[0..*, 0..*]): any[0..*, 0..*]

Parametri:

array_nd: The 1D or 2D array to be copied.

Esempio:

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
  

CountDims

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.

Sintassi:

svc.CountDims(array_nd: any): int

Parametri:

array_nd: The array to examine.

Esempio:


    Dim a(1 To 10, -3 To 12, 5)
    MsgBox SF_Array.CountDims(a) ' 3
  

Difference

Costruisce un insieme, in forma di matrice con indice iniziale zero, applicando l'operatore della differenza ai valori delle due matrici di partenza. Gli elementi risultanti derivano dalla prima matrice e non dalla seconda.
La matrice risultante è ordinata in modo crescente.
Entrambe le matrici di partenza devono essere riempite in modo omogeneo, i loro elementi devono essere scalari dello stesso tipo. Sono proibiti gli elementi Empty e Null.
Il confronto del testo può distinguere tra maiuscole e minuscole.

Sintassi:

svc.Difference(array1_1d: any[0..*], array2_1d: any[0..*], casesensitive: bool = False): any[0..*]

Parametri:

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).

Esempio:


    Dim a As Variant
    a = SF_Array.Difference(Array("A", "C", "A", "b", "B"), Array("C", "Z", "b"), True)
        ' ("A", "B")
  

ExportToTextFile

Scrivete in sequenza tutti gli elementi della matrice in un file di testo. Se il file esiste già, viene sovrascritto senza alcun avvertimento.

Sintassi:

svc.ExportToTextFile(array_1d: any[0..*], filename: str, [encoding: str]): bool

Parametri:

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").

Esempio:


    SF_Array.ExportToTextFile(Array("A","B","C","D"), "C:\Temp\A short file.txt")
  

ExtractColumn

Estrae una determinata colonna da una matrice bidimensionale memorizzandola in una nuova matrice.
I suoi limiti inferiore LBound e superiore UBound sono identici a quelli della prima dimensione della matrice di partenza.

Sintassi:

svc.ExtractColumn(array_2d: any[0..*, 0..*], columnindex: int): any[0..*, 0..*]

Parametri:

array_2d: The array from which to extract.

columnindex: The column number to extract - must be in the interval [LBound, UBound].

Esempio:


    'Crea una 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))
    'Estrae la terza colonna: |3, 6, 9|
    col = SF_Array.ExtractColumn(mat, 2)
  

ExtractRow

Estrae una determinata riga da una matrice bidimensionale memorizzandola in una nuova matrice.
I suoi limiti inferiore LBound e superiore UBound sono identici a quelli della seconda dimensione della matrice di partenza.

Sintassi:

svc.ExtractRow(array_2d: any[0..*, 0..*], rowindex: int): any[0..*, 0..*]

Parametri:

array_2d: The array from which to extract.

rowindex: The row number to extract - must be in the interval [LBound, UBound].

Esempio:


    'Crea una 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))
    'Estrae la prima riga: |1, 2, 3|
    row = SF_Array.ExtractRow(mat, 0)
  

Flatten

Accoda tutti i singoli elementi di una matrice e tutti gli elementi delle matrici nidificate in un'unica nuova matrice priva di matrici nidificate. Le matrici nidificate vuote vengono ignorate, mentre quelle che hanno un numero di dimensioni maggiore di uno non vengono appiattite.

Sintassi:

svc.Flatten(array_1d: any[0..*]): any[0..*]

Parametri:

array_1d: The pre-existing array, may be empty.

Esempio:


    Dim a As Variant
    a = SF_Array.Flatten(Array(Array(1, 2, 3), 4, 5))
        ' (1, 2, 3, 4, 5)
  
tip

Potete usare il metodo Flatten assieme ad altri metodi come Append o Prepend in modo da concatenare un insieme di matrici 1D in una singola matrice 1D.


Esempio:

Quello che segue è un esempio di come i due metodi Flatten e Append possono essere combinati per concatenare tre matrici.


    'Crea le tre matrici usate in questo esempio
    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)
    'Concatena le tre matrici in una singola 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)
  

ImportFromCSVFile

Importa i dati contenuti in un file CSV (valori separati da virgole). La virgola può essere sostituita con qualsiasi altro carattere.

Il formato CSV utilizzabile è descritto in Formati comuni IETF e tipi MIME per i file CSV (in inglese).

Ciascuna riga del file contiene un record intero (non è ammessa l'interruzione delle righe).
In ogni caso sequenze come \n, \t, ... non vengono modificate. Per gestirle usate il metodo SF_String.Unescape().

Il metodo restituisce una matrice bidimensionale le cui righe corrispondono a un singolo record letto dal file e le cui colonne corrispondono a un campo del record. Non effettua controlli in merito alla coerenza dei tipi di campo nelle colonne. Una presunzione migliore verrà fatta nell'identificazione dei tipi numerici e delle date.

Se una riga contiene un numero minore o maggiore di campi rispetto alla prima riga del file, verrà sollevata un'eccezione. In ogni caso le righe vuote saranno semplicemente ignorate. Se la dimensione del file eccede il numero limite di elementi (vedete all'interno del codice), viene sollevata un'eccezione e la matrice viene troncata.

Sintassi:

svc.ImportFromCSVFile(filename: str, delimiter: str = ',', dateformat: str = ''): any[0..*]

Parametri:

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.

Esempio:

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.

In Basic

    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
  
In Python

    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
  

IndexOf

Cerca un numero, una stringa o una data all'interno di una matrice unidimensionale. Il confronto del testo può distinguere tra maiuscole e minuscole.
Se la matrice è ordinata deve essere riempita in modo omogeneo, ciò significa che tutti gli elementi devono essere scalari dello stesso tipo (i valori Empty e Null non sono ammessi).
Il risultato del metodo non è prevedibile se una matrice viene passata come ordinata, ma in realtà non lo è.
Se la matrice è ordinata viene eseguita una ricerca di tipo binario, altrimenti viene semplicemente controllata da cima a fondo e i valori Empty e Null vengono ignorati.

Se la ricerca è stata infruttuosa, il metodo restituisce LBound(matrice di partenza) - 1.

Sintassi:

svc.IndexOf(array_1d: any[0..*], tofind: any, casesensitive: bool = False, sortorder: str = ''): int

Parametri:

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 "".

Esempio:


    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
  

Insert

Inserisce, prima di un determinato indice della matrice di partenza, tutti gli elementi elencati negli argomenti.
Gli argomenti vengono inseriti alla cieca. Ciascuno di essi dev'essere uno scalare di qualsiasi tipo o una matrice da nidificare.

Sintassi:

svc.Insert(array_1d: any[0..*], before: int, arg0: any, [arg1: any] ...): any[0..*]

Parametri:

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.

Esempio:


    Dim a As Variant
    a = SF_Array.Insert(Array(1, 2, 3), 2, "a", "b")
        ' (1, 2, "a", "b", 3)
  

InsertSorted

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.

Sintassi:

svc.InsertSorted(array_1d: any[0..*], item: any, sortorder: str = 'ASC', casesensitive: bool = False): any[0..*]

Parametri:

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).

Esempio:


    Dim a As Variant
    a = SF_Array.InsertSorted(Array("A", "C", "a", "b"), "B", CaseSensitive := True)
        ' ("A", "B", "C", "a", "b")
  

Intersection

Costruisce un insieme, in forma di matrice con indice iniziale zero, applicando alle due matrici l'operatore di intersezione degli insiemi. Gli elementi risultanti sono quelli presenti in entrambe le matrici.
La matrice risultante è ordinata in modo crescente.
Entrambe le matrici di partenza devono essere riempite in modo omogeneo, in altre parole, tutti i loro elementi devono essere scalari dello stesso tipo. Sono proibiti gli elementi Empty e Null.
Il confronto del testo può distinguere tra maiuscole e minuscole.

Sintassi:

svc.Intersection(array1_1d: any[0..*], array2_1d: any[0..*], casesensitive: bool = False): any[0..*]

Parametri:

array1_1d: The first input array.

array2_1d: The second input array.

casesensitive: Applies to arrays populated with text items (Default = False).

Esempio:


    Dim a As Variant
    a = SF_Array.Intersection(Array("A", "C", "A", "b", "B"), Array("C", "Z", "b"), True)
        ' ("C", "b")
  

Join2D

Unisce una matrice bidimensionale con due delimitatori, uno per le colonne e uno per le righe.

Sintassi:

svc.Join2D(array_2d: any [0..*, 0..*], [columndelimiter: str], [rowdelimiter: str], [quote: str]): str

Parametri:

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.

Esempio:


    ' 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
  

Prepend

Aggiunge, all'inizio della matrice di partenza, gli elementi elencati negli argomenti.

Sintassi:

svc.Prepend(array_1d: any[0..*], arg0: any, [arg1: any] ...): any[0..*]

Parametri:

array_1d: The pre-existing array, may be empty.

arg0, arg1, ...: A list of items to prepend to array_1d.

Esempio:


    Dim a As Variant
    a = SF_Array.Prepend(Array(1, 2, 3), 4, 5)
        ' (4, 5, 1, 2, 3)
  

PrependColumn

Inserisce una nuova colonna alla sinistra di una matrice bidimensionale. La matrice risultante ha gli stessi limiti inferiori della matrice bidimensionale di partenza.

Sintassi:

svc.PrependColumn(array_2d: any[0..*, 0..*], column: any[0..*]): any[0..*, 0..*]

Parametri:

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.

Esempio:


    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
  

PrependRow

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.

Sintassi:

svc.PrependRow(array_2d: any[0..*, 0..*], row: any[0..*]): any[0..*, 0..*]

Parametri:

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.

Esempio:


    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
  

RangeInit

Inizializza con valori numerici una nuova matrice avente base zero.

Sintassi:

svc.RangeInit(from: num, upto: num, [bystep: num]): num[0..*]

Parametri:

from: Value of the first item.

upto: The last item should not exceed UpTo.

bystep: The difference between two successive items (Default = 1).

Esempio:


    Dim a As Variant
    a = SF_Array.RangeInit(10, 1, -1)
        ' (10, 9, 8, 7, 6, 5, 4, 3, 2, 1)
  

Reverse

Restituisce la matrice unidimensionale invertita di quella iniziale.

Sintassi:

svc.Reverse(array_1d: any[0..*]): any[0..*]

Parametri:

array_1d: The array to reverse.

Esempio:


    Dim a As Variant
    a = SF_Array.Reverse(Array("a", 2, 3, 4))
        ' (4, 3, 2, "a")
  

Shuffle

Returns a random permutation of a one-dimensional array.

Sintassi:

svc.Shuffle(array_1d: any[0..*]): any[0..*]

Parametri:

array_1d: The array to shuffle.

Esempio:


    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)
  

Slice

Returns a subset of a one-dimensional array.

Sintassi:

svc.Slice(array_1d: any[0..*], from: int, [upto: int]): any[0..*]

Parametri:

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.

Esempio:


    Dim a As Variant
    a = SF_Array.Slice(Array(1, 2, 3, 4, 5), 1, 3) ' (2, 3, 4)
  

Sort

Ordina una matrice unidimensionale in modo ascendente o discendente. Il confronto di testi può distinguere tra maiuscole e minuscole.
La matrice deve essere riempita in modo omogeneo, ciò significa che gli elementi devono essere scalari dello stesso tipo.
Gli elementi Empty e Null sono ammessi. Convenzionalmente Empty < Null < qualunque altro valore scalare.

Sintassi:

svc.Sort(array_1d: any[0..*], sortorder: str, casesensitive: bool = False): any[0..*]

Parametri:

array_1d: The array to sort.

sortorder: It can be either "ASC" (default) or "DESC".

casesensitive: Only for string comparisons (Default = False).

Esempio:


    Dim a As Variant
    a = SF_Array.Sort(Array("a", "A", "b", "B", "C"), CaseSensitive := True)
        ' ("A", "B", "C", "a", "b")
  

SortColumns

Restituisce la permutazione delle colonne di una matrice bidimensionale, ordinata in base ai valori di una determinata riga.
La riga dev'essere riempita in modo omogeneo, il che significa che tutti gli elementi devono essere scalari dello stesso tipo. Gli
Elementi Empty e Null sono ammessi. Convenzionalmente Empty < Null < qualunque altro valore scalare.

Sintassi:

svc.SortColumns(array_2d: any[0..*, 0..*], rowindex: int, sortorder: str, casesensitive: bool = False): any[0..*, 0..*]

Parametri:

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).

Esempio:


    ' 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 |
  

SortRows

Restituisce una permutazione delle righe di una matrice bidimensionale, ordinata in base ai valori di una determinata colonna.
La colonna deve essere riempita in modo omogeneo, perciò tutti gli elementi devono essere scalari dello stesso tipo. Gli
Elementi Empty e Null sono ammessi. Convenzionalmente Empty < Null < qualunque altro valore scalare.

Sintassi:

svc.SortRows(array_2d: any[0..*, 0..*], columnindex: int, sortorder: str, casesensitive: bool = False): any[0..*, 0..*]

Parametri:

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).

Esempio:


    ' 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 |
  

Transpose

Swaps rows and columns in a two-dimensional array.

Sintassi:

svc.Transpose(array_2d: any[0..*, 0..*]): any[0..*, 0..*]

Parametri:

array_2d: The 2-dimensional array to transpose.

Esempio:


    ' 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
  

TrimArray

Rimuove da una matrice unidimensionale tutti gli elementi Null, Empty e di lunghezza zero.
Agli elementi di tipo stringa vengono rimossi gli spazi con la funzione Trim() di LibreOffice Basic.

Sintassi:

svc.TrimArray(array_1d: any[0..*]): any[0..*]

Parametri:

array_1d: The array to trim.

Esempio:


    Dim a As Variant
    a = SF_Array.TrimArray(Array("A", "B", Null, " D "))
        ' ("A", "B", "D")
  

Union

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.

Sintassi:

svc.Union(array1_1d: any[0..*], array2_1d: any[0..*], casesensitive: bool = False): any[0..*]

Parametri:

array1_1d: The first input array.

array2_1d: The second input array.

casesensitive: Applicable only if the arrays are populated with strings (Default = False).

Esempio:


    Dim a As Variant
    a = SF_Array.Union(Array("A", "C", "A", "b", "B"), Array("C", "Z", "b"), True)
        ' ("A", "B", "C", "Z", "b")
  

Unique

Costruisce un insieme di valori univoci derivati dalla matrice di partenza.
La matrice iniziale deve essere riempita in modo omogeneo, i suoi elementi devono essere scalari dello stesso tipo. Gli elementi Empty e Null non sono ammessi.
Il confronto del testo può distinguere tra maiuscole e minuscole.

Sintassi:

svc.Unique(array_1d: any[0..*], casesensitive: bool = False): any[0..*]

Parametri:

array_1d: The input array.

casesensitive: Applicable only if the array is populated with strings (Default = False).

Esempio:


    Dim a As Variant
    a = SF_Array.Unique(Array("A", "C", "A", "b", "B"), CaseSensitive := True)
        '  ("A", "B", "C", "b")
  
warning

All ScriptForge Basic routines or identifiers that are prefixed with an underscore character "_" are reserved for internal use. They are not meant be used in Basic macros or Python scripts.