Skip to content
StringUtil

Utils / StringUtil

StringUtil Class ​

String Tool

Table of contents ​

Methods ​

clipboardCopy(text: string): void other
Text copy
clipboardPaste(): string other
Text pasting, obtaining the text of the clipboard
format(str: string, ...param: any[]): string other
Replace the contents of {i} with subsequent parameters in sequence. I starts from 0, indicating the i+2 parameter. For details, please see the usage example.
isEmpty(str: string): boolean other
Determine whether the string is empty (null or "")
maskWordCheck(text: string): Promise<[maskWordCheck](mw.StringUtil.md#maskwordcheck)Result> other
Shielded word detect

Methods ​

clipboardCopy ​

• Static clipboardCopy(text): void other

Text copy

Parameters ​

text stringUsage: text copy to the cut
range: unlimited

Copy the string to the clipboard

Example usage: Create a script named StringExample, place it in the object bar, open the script, modify the original content to the following, save and run the game, and hello world will be displayed! Copy the text to the cut board, and then paste it elsewhere

ts
@Component
export default class StringExample extends Script {

    protected onStart(): void {
        if (!SystemUtil.isClient()) return;
        this.test();
    }

    private async test(): Promise<void> {
        StringUtil.clipboardCopy("hello world!");
    }

}
@Component
export default class StringExample extends Script {

    protected onStart(): void {
        if (!SystemUtil.isClient()) return;
        this.test();
    }

    private async test(): Promise<void> {
        StringUtil.clipboardCopy("hello world!");
    }

}

clipboardPaste ​

• Static clipboardPaste(): string other

Text pasting, obtaining the text of the clipboard

Returns ​

stringText of cut board

Usage example: create a script named StringExample, place it in the object bar, open the script, modify the original content to the following, save and run the game, and print the text of the cut to the console

ts
@Component
export default class StringExample extends Script {

    protected onStart(): void {
        if (!SystemUtil.isClient()) return;
        this.test();
    }

    private async test(): Promise<void> {
        let text = StringUtil.clipboardPaste();
        console.log("clipboardPaste", text);
    }

}
@Component
export default class StringExample extends Script {

    protected onStart(): void {
        if (!SystemUtil.isClient()) return;
        this.test();
    }

    private async test(): Promise<void> {
        let text = StringUtil.clipboardPaste();
        console.log("clipboardPaste", text);
    }

}

format ​

• Static format(str, ...param): string other

Replace the contents of {i} with subsequent parameters in sequence. I starts from 0, indicating the i+2 parameter. For details, please see the usage example.

Parameters ​

str stringString range to process: unlimited
...param any[]Replace sequence

Returns ​

stringNew string

Usage example: create a script named StringExample, place it in the object bar, open the script, modify the original content to the following, save and run the game, and the hello world will be output!

ts
@Component
export default class StringExample extends Script {

    protected onStart(): void {
        if (!SystemUtil.isClient()) return;
        this.test();
    }

    private async test(): Promise<void> {
        let targetString = StringUtil.format("{0} {1}{2}", "hello", "world", "!");
        console.log(targetString);
    }

}
@Component
export default class StringExample extends Script {

    protected onStart(): void {
        if (!SystemUtil.isClient()) return;
        this.test();
    }

    private async test(): Promise<void> {
        let targetString = StringUtil.format("{0} {1}{2}", "hello", "world", "!");
        console.log(targetString);
    }

}

isEmpty ​

• Static isEmpty(str): boolean other

Determine whether the string is empty (null or "")

Parameters ​

str stringThe string range to be judged: unlimited

Returns ​

booleanresult

Usage example: create a script named StringExample, place it in the object bar, open the script, modify the original content to the following, save and run the game, and output isEmpty1: false

ts
@Component
export default class StringExample extends Script {

    protected onStart(): void {
        if (!SystemUtil.isClient()) return;
        this.test();
    }

    private async test(): Promise<void> {
        let isEmpty1 = StringUtil.isEmpty("hello world!");
        console.log("isEmpty1: " + isEmpty1);
    }

}
@Component
export default class StringExample extends Script {

    protected onStart(): void {
        if (!SystemUtil.isClient()) return;
        this.test();
    }

    private async test(): Promise<void> {
        let isEmpty1 = StringUtil.isEmpty("hello world!");
        console.log("isEmpty1: " + isEmpty1);
    }

}

maskWordCheck ​

• Static maskWordCheck(text): Promise<maskWordCheckResult> other

Shielded word detect

Parameters ​

text stringText range to detect: unlimited

Returns ​

Promise<maskWordCheckResult>Detect result callback

Precautions

If an exception is encountered in the API, reject will be returned. To use the API, catch should be used to handle the exception

Example usage: Create a script named StringExample, place it in the object bar, open the script, modify the original content to the following, save and run the game, and it will output the message 'Mask word detection failed'

ts
@Component
export default class StringExample extends Script {

    protected onStart(): void {
        if (!SystemUtil.isClient()) return;
        this.test();
    }

    private async test(): Promise<void> {
        StringUtil.maskWordCheck ("King of Suicide"). then (result=>{
            if (!result.result) {
                Console. log ("masked word detect failed");
                Console. log ("hit text:"+result. hits);
            }
        }).catch(error => {
            Console.log ("Error in detect of masked words");
            console.log(error);
        });
    }

}
@Component
export default class StringExample extends Script {

    protected onStart(): void {
        if (!SystemUtil.isClient()) return;
        this.test();
    }

    private async test(): Promise<void> {
        StringUtil.maskWordCheck ("King of Suicide"). then (result=>{
            if (!result.result) {
                Console. log ("masked word detect failed");
                Console. log ("hit text:"+result. hits);
            }
        }).catch(error => {
            Console.log ("Error in detect of masked words");
            console.log(error);
        });
    }

}