StringUtils

Last Updated on : 2024-06-05 03:14:36download

This topic describes the utility methods related to strings.

Convert a string to an array

API operation name

hexStringToNumber

API description

Convert a specified hexadecimal string to an array.

Request parameter

Name Data type Description Required
bits string The hexadecimal string. Yes

Return parameter

Name Data type Description
result number The array that is converted from the specified hexadecimal string.

Sample request

import { Utils } from "tuya-panel-kit"; const { hexStringToNumber } = Utils.StringUtils; hexStringToNumber(bits); // Example: hexStringToNumber("AD03");

Sample response

[173, 3]

Convert hexadecimal to binary

API operation name

hexStringToBinString

API description

Convert a hexadecimal string to a binary string.

Request parameter

Name Data type Description Required
str string str is a hexadecimal string. Yes

Return parameter

Name Data type Description
result string The string that is converted from str. It contains 0 and 1.

Sample request

import { Utils } from "tuya-panel-kit"; const { hexStringToBinString } = Utils.StringUtils; hexStringToBinString(str); // Example: hexStringToBinString("A7B9"); hexStringToBinString("0709");

Sample response

1010011110111001 0000011100001001

Convert a string in camel case

API operation name

camelize

API description

Remove all hyphens (-) or underlines (_) from a string and capitalize the first character that follows the hyphens or underlines.

Request parameter

Name Data type Description Required
str string String Yes

Return parameter

Name Data type Description
result string The returned string in the camel case format.

Sample request

import { Utils } from "tuya-panel-kit"; const { camelize } = Utils.StringUtils; camelize(str); // Example: camelize("abb_aa-cc");

Sample response

abbAaCc