p5.js中的split()函数用于使用定界符将输入字符串分成多个部分。该分隔符可以是在输入字符串的每一段之间使用的任何字符串或符号。
用法:
split(String, Delimiter)
参数:该函数接受以下两个参数:
- String:这是要分割的输入字符串。
- Delimiter:这是用于分隔输入字符串数据的任何字符串或符号。
返回值:它返回输入字符串的分割数据。
以下程序说明了p5.js中的split()函数。
示例1:本示例使用split()函数使用Delemeter将输入字符串分成多个子字符串。
function setup() {  
   
    // Creating Canvas size 
    createCanvas(450, 150);  
}  
function draw() {  
       
    // Set the background color  
    background(220);  
     
    // Initializing the Strings 
    let String = 'GeeksforGeeks/Geeks/Geek/gfg';   
      
    // Calling to split() function. 
    let A = split(String, '/'); 
      
    // Set the size of text  
    textSize(16);  
       
    // Set the text color  
    fill(color('red'));  
     
    // Getting splitted string 
    text("Splitted string is: " + A[0], 50, 30);   
    text("Splitted string is: " + A[1], 50, 60);   
    text("Splitted string is: " + A[2], 50, 90);   
    text("Splitted string is: " + A[3], 50, 120); 
} 输出:

示例2:本示例使用split()函数使用Delemeter将输入字符串分成多个子字符串。
function setup() {  
   
    // Creating Canvas size 
    createCanvas(450, 150);  
}  
function draw() {  
       
    // Set the background color  
    background(220);  
     
    // Initializing the Strings 
    let String = '0&11&222&3333';   
      
    // Calling to split() function. 
    let A = split(String, '&'); 
      
    // Set the size of text  
    textSize(16);  
       
    // Set the text color  
    fill(color('red'));  
     
    // Getting splitted string 
    text("Splitted string is: " + A[0], 50, 30);   
    text("Splitted string is: " + A[1], 50, 60);   
    text("Splitted string is: " + A[2], 50, 90);   
    text("Splitted string is: " + A[3], 50, 120); 
} 输出:

参考: https://p5js.org/reference/#/p5/split
相关用法
- Node.js split()用法及代码示例
- Javascript String split()用法及代码示例
- d3.js d3.set.add()用法及代码示例
- PHP end()用法及代码示例
- PHP dir()用法及代码示例
- p5.js nfp()用法及代码示例
注:本文由纯净天空筛选整理自Kanchan_Ray大神的英文原创作品 p5.js | split() function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
