p5.js trim() function Last Updated : 11 May, 2023 Comments Improve Suggest changes Like Article Like Report The trim() function in p5.js is used to remove whitespace characters and tab from the beginning and end of an input String. This function is also used to remove the carriage return and Unicode "nbsp" character. Syntax: trim(Strings) or trim(Array_of_Strings) Parameters: This function accepts a parameter String or an array_of_strings which are going to be trimmed. Return Value: It returns the trimmed Strings. The below programs illustrate the trim() function in p5.js. Example-1: This example uses trim() function to remove whitespace characters from the beginning and end of a String. javascript function setup() { // Creating Canvas size createCanvas(450, 120); } function draw() { // Set the background color background(220); // Initializing the Strings and Array of strings let String = " Geeks "; let Array1 = [" 1 ", " 2 ", " 3 "]; let Array2 = [" a ", " A ", " b ", " B "]; // Calling to trim() function. let A = trim(String); let B = trim(Array1); let C = trim(Array2); // Set the size of text textSize(16); // Set the text color fill(color('red')); // Getting trimmed strings text("Trimmed string is: " + A, 50, 30); text("Trimmed strings are: " + B, 50, 60); text("Trimmed strings are: " + C, 50, 90); } Output: Example-2: This example uses trim() function to remove the tab from the beginning and end of a String. javascript function setup() { // Creating Canvas size createCanvas(450, 120); } function draw() { // Set the background color background(220); // Initializing the Strings and Array of strings let String = " GeeksforGeeks "; let Array1 = [" 5 ", " 6 ", " 7 "]; let Array2 = [" Delhi ", " Mumbai ", " Kolkata ", " Patna "]; // Calling to trim() function. let A = trim(String); let B = trim(Array1); let C = trim(Array2); // Set the size of text textSize(16); // Set the text color fill(color('red')); // Getting trimmed strings text("Trimmed string is: " + A, 50, 30); text("Trimmed strings are: " + B, 50, 60); text("Trimmed strings are: " + C, 50, 90); } Output: Reference: https://p5js.org/reference/#/p5/trim Comment More infoAdvertise with us Next Article p5.js trim() function K Kanchan_Ray Follow Improve Article Tags : JavaScript Web Technologies JavaScript-p5.js Similar Reads Node.js trim() function The trim() function is a string function of Node.js which is used to remove white spaces from the string. Syntax: string.trim() Parameter: This function does not accept any parameter. Return Value: The function returns the string without white spaces. The below programs demonstrate the working of tr 1 min read PHP trim() Function The trim() function in PHP is an inbuilt function which removes whitespaces and also the predefined characters from both sides of a string that is left and right. Related Functions: PHP | ltrim() Function PHP | rtrim() Function Syntax: trim($string, $charlist) Parameters:The function accepts one man 2 min read 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 2 min read p5.js unchar() function The unchar() function in p5.js is used to convert a single-character string into its corresponding integer representation. This function is just opposite to the char() function. Syntax: unchar(value) Parameters: This function accepts single parameter value which is to be converted into its correspon 2 min read p5.js subset() function The subset() function in p5.js is used to get the subset of the given array elements. This function extracts the elements from an existing array. Syntax: subset(Array, Start, Count) Parameters: This function accepts three parameters as mentioned above and described below: Array: This parameter hold 2 min read Node.js GM trim() Function The trim() function is an inbuilt function in the GraphicsMagick library which is used to remove edges that are exactly the same color as the corner pixels. The function returns the true value of success. Syntax: trim() Parameters: This function does not accept any parameters. Return Value: This f 1 min read p5.js shorten() function The shorten() function in p5.js is used to decrease the number of elements of the given array by one. Syntax: shorten(Array) Parameters: This function accepts a parameter Array whose elements are to be shortened by one. Return Value: It returns the shortened array. Below program illustrates the shor 1 min read p5.js textLeading() Function The textAlign() function in p5.js is used to set the spacing, in pixels, between lines of text. This function is used in all subsequent calls to the text() function. Syntax: textLeading(leading) Parameters: This function accepts single argument leading which stores the size in pixels for spacing bet 2 min read p5.js join() function The join() function in p5.js is used to join the input array of strings into a single string using separator. This separator might be any character which gets their position in between two strings of the input array. Syntax: join(Array, Separator) Parameters: This function accepts two parameters as 2 min read Like