Truncate utf8 encoded string, specify width (not length) from first byte


Intercepts utf8 encoded string, and specifies the width (non length) from the first byte,

It is suitable for the same width interception of limited string length such as news headlines

The results show that the width difference between Chinese and English is the biggest, and the larger the intercepting width is, the more obvious it is

Code example


This work adoptsCC agreementThe author and the link to this article must be indicated in the reprint

When your talent can’t support your ambition, calm down and study

Recommended Today

Explain module, import and export in JavaScript

Author: Tania rascia Crazy technology house Original text:… In the era of the Internet, websites are mainly developed with HTML and CSS. If you load JavaScript into a page, it usually provides effects and interactions in the form of small fragments. Generally, all JavaScript code is written in a file and loaded into a filescriptTag. […]