Skip to content

cutCHSString

Cut a Chinese string, counting Chinese characters as 2 bytes.

Usage

js
import { cutCHSString } from 'js-cool'

Signature

typescript
function cutCHSString(str: string, len?: number, hasDot?: boolean): string

Parameters

ParameterTypeDescription
strstringThe string to cut
lennumberMaximum length (default: string length)
hasDotbooleanAdd ellipsis if truncated (default: false)

Returns

string - The truncated string.

Examples

js
cutCHSString('Hello世界', 7) // 'Hello世'
cutCHSString('Hello世界你好', 8, true) // 'Hello世...'
cutCHSString('中文测试字符串', 6) // '中文测试'

Released under the MIT License.