graphemeSplit()方法用于将指定的字符串划分为用户感知的单个单位,即指定字符串的每个字符都将转换为单个字符串单位。
用法:
graphemeSplit(textstring)
参数:此方法接受如上所述和以下描述的参数:
- textstring:此参数保存要分割的字符串。
返回值:此方法返回包含字素的数组,该字素是划分的字符。
范例1:
Javascript
<!DOCTYPE html>
<html>
<head>
<script src=
"https://cdnjs.cloudflare.com/ajax/libs/fabric.js/3.6.2/fabric.min.js" >
</script>
<script type="text/javascript" src=
"https://cdnjs.cloudflare.com/ajax/libs/fabric.js/3.6.2/fabric.min.js.map">
</script>
<script type="text/javascript" src=
"https://cdnjs.cloudflare.com/ajax/libs/fabric.js/3.6.2/fabric.js">
</script>
</head>
<body>
<script type="text/javascript">
console.log(fabric.util.string.graphemeSplit("GFG"));
console.log(fabric.util.string.graphemeSplit("G F G"));
</script>
</body>
</html>
输出:
["G","F","G"] ["G"," ","F"," ","G"]
范例2:
Javascript
<!DOCTYPE html>
<html>
<head>
<script src=
"https://cdnjs.cloudflare.com/ajax/libs/fabric.js/3.6.2/fabric.min.js" >
</script>
<script type="text/javascript" src=
"https://cdnjs.cloudflare.com/ajax/libs/fabric.js/3.6.2/fabric.min.js.map">
</script>
<script type="text/javascript" src=
"https://cdnjs.cloudflare.com/ajax/libs/fabric.js/3.6.2/fabric.js">
</script>
</head>
<body>
<script type="text/javascript">
console.log("Using graphemeSplit() Function:");
var value = "12ab";
console.log(fabric.util.string.graphemeSplit(value));
console.log("Without using graphemeSplit() Function:");
var value="12ab";
console.log(value);
</script>
</body>
</html>
输出:
Using graphemeSplit() Function: ["1","2","a","b"] Without using graphemeSplit() Function: 12ab
相关用法
- Lodash _.method()用法及代码示例
- Node.js Http2ServerRequest.method用法及代码示例
- Node.js http.IncomingMessage.method用法及代码示例
- Javascript dataView.getInt16()用法及代码示例
- Javascript RegExp toString()用法及代码示例
- Node.js URLSearchParams.has()用法及代码示例
- JavaScript Math cosh()用法及代码示例
- HTML DOM isEqualNode()用法及代码示例
- JavaScript Date toLocaleTimeString()用法及代码示例
- Node.js crypto.createHash()用法及代码示例
- Node.js writeStream.clearLine()用法及代码示例
- Node.js fs.link()用法及代码示例
- JavaScript Math random()用法及代码示例
- JavaScript Math round()用法及代码示例
- Javascript toString()用法及代码示例
- Javascript Number.isInteger( )用法及代码示例
- Javascript Number.isFinite()用法及代码示例
- Javascript toFixed()用法及代码示例
- Javascript toPrecision()用法及代码示例
- JavaScript Math abs()用法及代码示例
- JavaScript Math sqrt()用法及代码示例
- JavaScript Math floor()用法及代码示例
注:本文由纯净天空筛选整理自Kanchan_Ray大神的英文原创作品 Fabric.js graphemeSplit() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。