Saturday, August 30, 2025
HomeLanguagesJavascriptp5.js split() function

p5.js split() function

The split() function in p5.js is used to break the input string into pieces using a delimiter. This delimiter could be any string or symbol used between each piece of the input string. Syntax:

split(String, Delimiter)

Parameters: This function accepts two parameters which are described below:

  • String: This is the input string which are to be splitted.
  • Delimiter: This is any string or symbol used to separate the data of the input string.

Return Value: It returns the splitted data of the input string. Below programs illustrate the split() function in p5.js. Example 1: This example uses split() function to break the input string into pieces of substring using delimiter. 

javascript




function setup() { 
   
    // Creating Canvas size
    createCanvas(450, 150); 
} 
function draw() { 
       
    // Set the background color 
    background(220); 
     
    // Initializing the Strings
    let String = 'neveropen/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);
} 


Output: Example 2: This example uses split() function to break the input string into pieces of substring using delimiter. 

javascript




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);
} 


Output: Reference: https://p5js.org/reference/#/p5/split

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32249 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6617 POSTS0 COMMENTS
Nicole Veronica
11792 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11838 POSTS0 COMMENTS
Shaida Kate Naidoo
6731 POSTS0 COMMENTS
Ted Musemwa
7013 POSTS0 COMMENTS
Thapelo Manthata
6689 POSTS0 COMMENTS
Umr Jansen
6701 POSTS0 COMMENTS