ScriptForge.Array service

Egydimenziós (vektorok) és kétdimenziós (mátrixok) tömbök manipulálására és transzformálására szolgáló módszerek gyűjteménye. Ez magában foglalja a halmazműveleteket, a rendezést, a szöveges fájlokból való importálást és a szöveges fájlba való exportálást.

Arrays with more than two dimensions cannot be used with the methods in this service, the only exception being the CountDims method that accepts Arrays with any number of dimensions.

Array items may contain any type of value, including (sub)arrays.

A szolgáltatás igénybevétele

Before using the Array service the ScriptForge library needs to be loaded using:


    GlobalScope.BasicLibraries.loadLibrary("ScriptForge")
  

Loading the library will create the SF_Array object that can be used to call the methods in the Array service.

The following code snippets show the various ways to call methods in the Array service (the Append method is used as an example):


    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

Mivel a Python beépített lista és tuple támogatással rendelkezik, az Array szolgáltatás legtöbb metódusa csak Basic parancsfájlok számára érhető el. Az egyetlen kivétel az ImportFromCSVFile, amely Basic és Python nyelven is támogatott.


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

A legtöbb metódus első argumentuma a figyelembe veendő tömbobjektum. Ezt mindig hivatkozással adjuk át, és változatlanul hagyjuk. Az olyan metódusok, mint a Hozzáfűzés, Eléfűzés stb. a végrehajtásuk után egy új tömbobjektumot adnak vissza.


Append

Appends the items listed as arguments to the end of the input array.

Szintaxis:

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

Paraméterek:

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

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

Példa:


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

AppendColumn

Appends a new column to the right side of a two dimensional array. The resulting array has the same lower bounds as the initial two dimensional array.

Szintaxis:

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

Paraméterek:

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.

Példa:


    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

Append to the bottom of a two dimension array a new row. The resulting array has the same lower bounds as the initial two dimension array.

Szintaxis:

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

Paraméterek:

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.

Példa:


    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

Annak ellenőrzése, hogy egy egydimenziós tömb tartalmaz-e egy bizonyos számot, szöveget vagy dátumot. A szöveg összehasonlítása lehet nagy- és kisbetű-érzékeny vagy nem.
A rendezett bemeneti tömböket homogén módon kell kitölteni, azaz minden elemnek azonos típusú skalárnak kell lennie (az Empty és Null elemek tiltottak).
A módszer eredménye kiszámíthatatlan, ha a tömböt rendezettnek jelentjük be, de a valóságban nem az.
A rendezett tömbökön bináris keresés történik. Egyébként a tömböket egyszerűen felülről lefelé vizsgálja, és az Empty és Null elemeket figyelmen kívül hagyja.

Szintaxis:

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

Paraméterek:

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

Példa:


    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

Store the content of a 2-columns array into a ScriptForge.Dictionary object.
The key will be extracted from the first column, the item from the second.

Szintaxis:

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

Paraméterek:

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

Példa:


    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.

Szintaxis:

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

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

Paraméterek:

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

Példa:

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
  

A Copy metódus használatával a teljes Array objektum másolata készül. Az alábbi példában a és b különböző objektumok, és b értékeinek megváltoztatása nem befolyásolja a értékeit.


    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

Megszámolja egy tömb dimenzióinak számát. Az eredmény nagyobb lehet kettőnél.
Ha az argumentum nem tömb, -1-et ad vissza
Ha a tömb nincs inicializálva, 0-t ad vissza.

Szintaxis:

svc.CountDims(array_nd: any): int

Paraméterek:

array_nd: The array to examine.

Példa:


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

Difference

Állítson össze egy halmazt, nulla alapú tömbként, a különbség-operátor alkalmazásával a két bemeneti tömbre. A kapott elemek az első tömbből származnak, a másodikból nem.
A kapott tömb növekvő sorrendbe van rendezve.
Mindkét bemeneti tömböt homogén módon kell feltölteni, elemeiknek azonos típusú skalároknak kell lenniük. A Empty és Null elemek tiltottak.
A szöveg összehasonlítása lehet nagy- és kisbetű érzékeny vagy nem.

Szintaxis:

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

Paraméterek:

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

Példa:


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

ExportToTextFile

Write all items of the array sequentially to a text file. If the file exists already, it will be overwritten without warning.

Szintaxis:

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

Paraméterek:

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

Példa:


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

ExtractColumn

Egy kétdimenziós tömbből egy adott oszlop kivonása új tömbként.
Az alsó LBound és a felső UBound határai megegyeznek a bemeneti tömb első dimenziójának határaival.

Szintaxis:

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

Paraméterek:

array_2d: The array from which to extract.

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

Példa:


    'Creates a 3x3 matrix: |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))
    'Extracts the third column: |3, 6, 9|
    col = SF_Array.ExtractColumn(mat, 2)
  

ExtractRow

Egy kétdimenziós tömbből egy adott sor kivonása új tömbként.
Az alsó LBound és a felső UBound határai megegyeznek a bemeneti tömb első dimenziójának határaival.

Szintaxis:

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

Paraméterek:

array_2d: The array from which to extract.

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

Példa:


    'Creates a 3x3 matrix: |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))
    'Extracts the first row: |1, 2, 3|
    row = SF_Array.ExtractRow(mat, 0)
  

Flatten

Egy tömb minden egyes elemét és az altömbök összes elemét egy új, altömbök nélküli tömbbe halmozza. Az üres altömböket figyelmen kívül hagyja, és az egynél nagyobb dimenziószámú altömböket nem lapítja ki.

Szintaxis:

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

Paraméterek:

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

Példa:


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

You can use the Flatten method along with other methods such as Append or Prepend to concatenate a set of 1D arrays into a single 1D array.


Példa:

Next is an example of how the methods Flatten and Append can be combined to concatenate three arrays.


    'Creates three arrays for this example
    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)
    'Concatenates the three arrays into a single 1D array
    Dim arr as Variant
    arr = SF_Array.Flatten(SF_Array.Append(a, b, c))
    '(1, 2, 3, 4, 5, 6, 7, 8, 9)
  

ImportFromCSVFile

Import the data contained in a comma-separated values (CSV) file. The comma may be replaced by any character.

The applicable CSV format is described in IETF Common Format and MIME Type for CSV Files.

Each line in the file contains a full record (line splitting is not allowed).
However sequences like \n, \t, ... are left unchanged. Use SF_String.Unescape() method to manage them.

A módszer egy kétdimenziós tömböt ad vissza, amelynek sorai a fájlból beolvasott egyetlen rekordnak, oszlopai pedig a rekord egy mezőjének felelnek meg. Nem történik ellenőrzés a mezőtípusok oszlopok közötti koherenciájára vonatkozóan. A numerikus és dátumtípusok azonosítására a lehető legjobb becslés történik.

Ha egy sor kevesebb vagy több mezőt tartalmaz, mint a fájl első sora, a rendszer kivételt fog generálni. Az üres sorokat azonban egyszerűen figyelmen kívül hagyja. Ha a fájl mérete meghaladja az elemek számának határértékét (lásd a kódon belül), figyelmeztetés jelenik meg, és a tömb le lesz vágva.

Szintaxis:

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

Paraméterek:

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: Egy speciális mechanizmus kezeli a dátumokat, amikor a dateformat "ÉÉÉÉ-HH-NN", "NN-HH-ÉÉÉÉ" vagy "HH-NN-ÉÉÉÉ". A kötőjel (-) helyettesíthető ponttal (.), osztásjellel (/) vagy szóközzel. Más dátumformátumokat a rendszer figyelmen kívül hagy. Az üres "" karakterláncot tartalmazó dátumokat normál szövegnek kell tekinteni.

Példa:

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.

A Basic nyelvben

    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
  
A Python nyelvben

    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

Egy egydimenziós tömbben keres egy számot, egy karakterláncot vagy egy dátumot. A szövegek összehasonlítása lehet nagy- és kisbetű-érzékeny vagy nem.
Ha a tömb rendezett, akkor homogén módon kell kitölteni, ami azt jelenti, hogy minden elemnek azonos típusú skalárnak kell lennie (Empty és Null elemek tiltottak).
A metódus eredménye kiszámíthatatlan, ha a tömböt rendezettnek jelentjük be, de valójában nem az.
A rendezett tömbökön bináris keresés történik. Egyébként a tömböket egyszerűen felülről lefelé vizsgálja, és az Empty és Null elemeket figyelmen kívül hagyja.

A módszer LBound(input array) - 1 értéket ad vissza, ha a keresés nem volt sikeres.

Szintaxis:

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

Paraméterek:

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

Példa:


    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

A bemeneti tömb adott indexe elé beszúrja az argumentumként felsorolt elemeket.
Az argumentumok vakon kerülnek beszúrásra. Mindegyik egy tetszőleges típusú skalár vagy egy altömb.

Szintaxis:

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

Paraméterek:

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.

Példa:


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

InsertSorted

Rendezett tömbbe egy új elemet a helyére szúr be.
A tömböt homogén módon kell feltölteni, ami azt jelenti, hogy minden elemnek azonos típusú skalárnak kell lennie.
Empty és Null elemek használata tilos.

Szintaxis:

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

Paraméterek:

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

Példa:


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

Intersection

Állítson össze egy halmazt, nulla alapú tömbként, a metszethalmaz operátor alkalmazásával a két bemeneti tömbre. Az eredményül kapott elemek mindkét tömbben benne vannak.
A kapott tömb növekvő sorrendbe van rendezve.
Mindkét bemeneti tömböt homogén módon kell kitölteni, más szóval minden elemnek azonos típusú skalárnak kell lennie. Az Empty és Null elemek tiltottak.
A szöveg összehasonlítása lehet nagy- és kisbetű érzékeny vagy nem.

Szintaxis:

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

Paraméterek:

array1_1d: The first input array.

array2_1d: The second input array.

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

Példa:


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

Join2D

Join a two-dimensional array with two delimiters, one for the columns, one for the rows.

Szintaxis:

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

Paraméterek:

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.

Példa:


    ' 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

Prepend at the beginning of the input array the items listed as arguments.

Szintaxis:

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

Paraméterek:

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

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

Példa:


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

PrependColumn

Prepend to the left side of a two dimension array a new column. The resulting array has the same lower boundaries as the initial two dimension array.

Szintaxis:

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

Paraméterek:

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.

Példa:


    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.

Szintaxis:

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

Paraméterek:

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.

Példa:


    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

Initialize a new zero-based array with numeric values.

Szintaxis:

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

Paraméterek:

from: Value of the first item.

upto: The last item should not exceed UpTo.

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

Példa:


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

Reverse

Return the reversed one dimension input array.

Szintaxis:

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

Paraméterek:

array_1d: The array to reverse.

Példa:


    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.

Szintaxis:

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

Paraméterek:

array_1d: The array to shuffle.

Példa:


    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.

Szintaxis:

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

Paraméterek:

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.

Példa:


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

Sort

Egy egydimenziós tömb rendezése növekvő vagy csökkenő sorrendbe. A szöveges összehasonlítások lehetnek nagy- és kisbetű-érzékenyek vagy sem.
A tömböt homogén módon kell kitölteni, ami azt jelenti, hogy az elemeknek azonos típusú skalároknak kell lenniük.
Empty és Null elemek megengedettek. Hagyományosan Empty < Null < bármely más skalárérték.

Szintaxis:

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

Paraméterek:

array_1d: The array to sort.

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

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

Példa:


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

SortColumns

Egy kétdimenziós tömb oszlopainak permutációját adja vissza egy adott sor értékei alapján rendezve.
A sort homogén módon kell kitölteni, ami azt jelenti, hogy minden elemnek azonos típusú skalárnak kell lennie.
Empty és Null elemek megengedettek. Hagyományosan Empty < Null < bármely más skalárérték.

Szintaxis:

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

Paraméterek:

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

Példa:


    ' 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

Egy kétdimenziós tömb sorainak permutációját adja vissza egy adott oszlop értékei alapján rendezve.
Az oszlopot homogén módon kell kitölteni, ezért minden elemnek azonos típusú skalárnak kell lennie.
Empty és Null elemek megengedettek. Hagyományosan Empty < Null < bármely más skalárérték.

Szintaxis:

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

Paraméterek:

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

Példa:


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

Szintaxis:

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

Paraméterek:

array_2d: The 2-dimensional array to transpose.

Példa:


    ' 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

Remove from a one dimension array all Null, Empty and zero-length entries.
String items are trimmed with LibreOffice Basic Trim() function.

Szintaxis:

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

Paraméterek:

array_1d: The array to trim.

Példa:


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

Union

Egy halmazt hoz létre, nullás tömbként, az unió operátor alkalmazásával a két bemeneti tömbre. A kapott elemek a két tömb bármelyikéből származnak.
A kapott tömböt növekvő sorrendbe rendezi.
Mindkét bemeneti tömböt homogén módon kell feltölteni, elemeiknek azonos típusú skalároknak kell lenniük. Az Empty és Null elemek tiltottak.
A szöveg összehasonlítása lehet nagy- és kisbetű érzékeny vagy nem.

Szintaxis:

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

Paraméterek:

array1_1d: The first input array.

array2_1d: The second input array.

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

Példa:


    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

A bemeneti tömbből származó egyedi értékek készletének összeállítása.
A bemeneti tömböt homogén módon kell feltölteni, elemeinek azonos típusú skalároknak kell lenniük. Az Empty és Null elemek tiltottak.
A szöveg összehasonlítása lehet nagy- és kisbetű érzékeny vagy nem.

Szintaxis:

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

Paraméterek:

array_1d: The input array.

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

Példa:


    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.


Támogasson minket!