当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Fabric.js graphemeSplit()用法及代码示例


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

相关用法


注:本文由纯净天空筛选整理自Kanchan_Ray大神的英文原创作品 Fabric.js graphemeSplit() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。