[mxcad_2d API documentation] (../README. md)/[2d] (../modules/2d. md)/McGeSringArray
Class: McGeStringArray
2d.McGeStringArray
McGeSringArray represents an array container for a set of string values.
Description
This class is used to store and process string collections, commonly used for layer names, line type names, text style names Batch management of CAD string information such as layout names. It supports adding, reading, modifying, traversing, and clearing.
Example
import { McGeStringArray } from "mxcad";
const names = new McGeStringArray();
names.append("Layer1");
names.append("Layer2");
Console. log (names. at (0))//Get the element value with index 0;
Console. log (names. length())//Get the length of the array;Table of contents
Constructors
Properties
Methods
Constructors
constructor
• new McGeStringArray(imp?)
Constructor.
Parameters
| Name | Type | Description |
|---|---|---|
imp? | Object | Internal constructor |
Properties
imp
• imp: any
Internal implementation object
Methods
append
▸ append(val): void
Add a value
Parameters
| Name | Type | Description |
|---|---|---|
| Val | string | string |
Returns
void
at
▸ at(index, decodeFromGb2312?): string
Obtain the values of data elements based on the array index
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| Index | number | undefined | array index |
decodeFromGb2312 | boolean | true | - |
Returns
string
character string
clear
▸ clear(): void
Clear the array
Returns
void
Example
import { McGeStringArray } from "mxcad";
const array = new McGeStringArray();
array.append("apple");
array.append("banana");
array.clear();
console.log(array.length()); // Output: 0copy
▸ copy(val): McGeStringArray
Copy the value of the object
Parameters
| Name | Type |
|---|---|
val | McGeStringArray |
Returns
Example
import { McGeStringArray } from "mxcad";
const array1 = new McGeStringArray();
const array2 = new McGeStringArray();
array2.append("apple");
array2.append("banana");
//Copy the value of array2 to array1
array1.copy(array2);forEach
▸ forEach(call, decodeFromGb2312?): void
Traverse the array
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| Call | (val: string, index: number)=>void | undefined | callback function |
decodeFromGb2312 | boolean | true | - |
Returns
void
Example
import { McGeStringArray } from "mxcad";
const array = new McGeStringArray();
array.append("apple");
array.append("banana");
array.forEach((val, index) => {
console.log(`Index ${index}: Value ${val}`);
});
//Output:
// Index 0: Value apple
// Index 1: Value bananalength
▸ length(): number
Return the length of the array
Returns
number
Array length
setAt
▸ setAt(index, val, decodeFromGb2312?): void
Set the value of data elements through array indexing
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| Index | number | undefined | array index |
| Val | string | undefined | string |
decodeFromGb2312 | boolean | true | - |
Returns
void
Example
import { McGeStringArray } from "mxcad";
const array = new McGeStringArray();
array.append("apple");
array.append("banana");
array.setAt(0, "orange");
console.log(array.at(0)); // Output: "orange"