Array

Dividing String into Array

Cut the input string to the specified length and make it into an array.

Example

Cut the value input in the Edit component by the specified length and return it as an array.

sample_array_01.xfdl

Core features used in the example

push

This is the method that adds the last value to the array.

How to implement an example

1

Configuring Form Screen

Place the Edit component and Button component.

2

Writing onclick Event Function

When the button is clicked, an array is created, and the string is cut and added to the array, repeating the length of the input string.

this.Button00_onclick = function(obj:nexacro.Button,e:nexacro.ClickEventInfo)
{
	var arrArray = new Array();
	var sString = this.Edit00.value;
	var nSize = 3;
    for (var i = 0; i < sString.length; i+=nSize)
    {        
        arrArray.push(sString.substr(i, nSize)); 
    }
	this.Edit01.value = arrArray;
};

In the case of the example, the actual array contains values as shown below.

3

Checking with QuickView

Run it with QuickView (Ctrl + F6) and enter the value to check.

Removing Duplicate Elements

Convert the input string into an array and remove duplicate elements.

Example

The value entered in the Edit component is cut based on comma (,) and converted to an array, and the result of removing duplicate elements is returned.

sample_array_02.xfdl

Core features used in the example

split

Splits the string according to the separator and returns it as an array.

How to implement an example

1

Configuring Form Screen

Place the Edit component and Button component.

2

Writing onclick Event Function

When the button is clicked, an array is created, and the string is cut and added to the array, repeating the length of the input string.

this.Button00_onclick = function(obj:nexacro.Button,e:nexacro.ClickEventInfo)
{
	var aRtn = this.fn_distinct(this.Edit00.value);
	this.Edit01.value = aRtn;
};

this.fn_distinct = function(sParam)
{
    var aData = new Array();
    aData = sParam.split(",");
	
    var aRtn = new Array();
    var bFlag;
    var vDist;
    
    for (var i = 0; i < aData.length; i++)
    {
        vDist = aData[i];
        bFlag = false;
        for (var j = 0; j < aRtn.length; j++)
        {
			if (aRtn[j] == vDist)
            {
                bFlag = true;
                break;
            }
        }
        if (bFlag == false)
        {
			aRtn[aRtn.length] = vDist;            
        }
    }
    return aRtn;  
}

In the example, duplicate values were removed by comparing all the elements in the array one by one. It does not make a big difference if the array is not large, but if the size is large, then it might be faster to sort the array first and then remove the duplicate values.

3

Checking with QuickView

Run it with QuickView (Ctrl + F6) and enter the value to check.

Sorting Number Array

Converts the input string into an array and returns the sorted values.

Example

The value entered in the Edit component is cut based on comma (,) and converted into an array, and the values sorted by string or number are displayed.

sample_array_03.xfdl

Core features used in the example

sort

Returns a new sorted array. By specifying the function in the parameter, you can change the sort order to the desired format.

How to implement an example

1

Configuring Form Screen

Place the Edit component and Button component.

2

Writing onclick Event Function

When the button is clicked, an array is created, and the string is cut and added to the array, repeating the length of the input string.

this.Button00_onclick = function(obj:nexacro.Button,e:nexacro.ClickEventInfo)
{
	var arrNo = this.Edit00.value.split(",");
	this.fn_arrayNoSort(arrNo);	
 	this.fn_arrayStringSort(arrNo);
};

this.fn_arrayStringSort = function(arrNo)
{
    this.Edit01.value = arrNo.sort();
};

this.fn_arrayNoSort = function(arrNo)
{
	this.Edit02.value = arrNo.sort(function(a, b){return a-b});
};

3

Checking with QuickView

Run it with QuickView (Ctrl + F6) and enter the value to check.

Creating 2D Array

You can implement a type similar to a two-dimensional array. This is precisely how you place the elements of an array inside an array.

Example

If you specify the number of rows and columns of the two-dimensional array to be created, then the two-dimensional form is created and displayed in the TextArea component.

sample_array_04.xfdl

Core features used in the example

new Array()

The Array object is created even if [] is assigned without creating the Array object with the new Array().

How to implement an example

1

Configuring Form Screen

Place the Edit component and Button component.

2

Writing onclick Event Function

When the button is clicked, an array is created and a two-dimensional array format is created by repeating the input string length.

this.Button00_onclick = function(obj:nexacro.Button,e:nexacro.ClickEventInfo)
{
	var arrValue = [];
	var nLen1 = this.Edit00.value;
	var nLen2 = this.Edit01.value;
	for (var i = 0; i < nLen1; i++)
	{
		arrValue[i] = new Array();
		for (var j = 0; j < nLen2; j++)
		{
			arrValue[i][j] = " [" + i + "][" + j + "]";
		}
	}
	var sRtn = "";
    for (var i = 0; i < nLen1; i++)
    {
        sRtn += arrValue[i] + "\n";
    }	
	this.TextArea00.value = sRtn;
};

3

Checking with QuickView

Run it with QuickView (Ctrl + F6) and enter the value to check.