Skip to content

[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

ts
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

NameTypeDescription
imp?ObjectInternal constructor

Properties

imp

imp: any

Internal implementation object

Methods

append

append(val): void

Add a value

Parameters

NameTypeDescription
Valstringstring

Returns

void


at

at(index, decodeFromGb2312?): string

Obtain the values of data elements based on the array index

Parameters

NameTypeDefault valueDescription
Indexnumberundefinedarray index
decodeFromGb2312booleantrue-

Returns

string

character string


clear

clear(): void

Clear the array

Returns

void

Example

ts
import { McGeStringArray } from "mxcad";

  const array = new McGeStringArray();
  array.append("apple");
  array.append("banana");

  array.clear();
console.log(array.length()); //  Output: 0

copy

copy(val): McGeStringArray

Copy the value of the object

Parameters

NameType
valMcGeStringArray

Returns

McGeStringArray

Example

ts
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

NameTypeDefault valueDescription
Call(val: string, index: number)=>voidundefinedcallback function
decodeFromGb2312booleantrue-

Returns

void

Example

ts
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 banana

length

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

NameTypeDefault valueDescription
Indexnumberundefinedarray index
Valstringundefinedstring
decodeFromGb2312booleantrue-

Returns

void

Example

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