Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • p5.js-Environment
  • p5.js-Color
  • p5.js-Shape
  • p5.js-Constants and Structure
  • p5.js-DOM and Rendering
  • p5.js-Transform
  • p5.js-Data
  • p5.js-Events
  • p5.js-Image
  • p5.js-IO
  • p5.js-Math
  • p5.js-Typography
  • p5.js-Lights & Camera
  • JavaScript
  • Web Technology
Open In App
Next Article:
p5.js split() function
Next article icon

p5.js str() function

Last Updated : 22 Aug, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report
The str() function in p5.js is used to convert the given boolean, string and number value into its string representation. Syntax:
str(value)
Parameters: This function accepts single parameter value which is to be converted into its string representation. This value might be integer, float, string, boolean, negative or positive value and array of values. Return Value: It returns the converted string representation. Below programs illustrate the str() function in p5.js: Example 1: This example uses str() function to convert the given input value into its corresponding string representation. javascript
function setup() {        // Creating Canvas size     createCanvas(600, 160);  }    function draw() {            // Set the background color      background(220);          // Initializing some values     let Value1 = 12;     let Value2 = 12.5;     let Value3 = -7.9;     let Value4 = -6;     let Value5 = "6";         // Calling to str() function.     let A = str(Value1);     let B = str(Value2);     let C = str(Value3);     let D = str(Value4);     let E = str(Value5);           // Set the size of text      textSize(16);            // Set the text color      fill(color('red'));          // Getting string representation     text("String representation of value 12 is: " + A, 50, 30);     text("String representation of value 12.5 is: " + B, 50, 60);     text("String representation of value -7.9 is: " + C, 50, 90);     text("String representation of value -6 is: " + D, 50, 110);     text("String representation of string '6' is: " + E, 50, 140); }  
Output: Example 2: This example uses str() function to convert the given input value into its corresponding string representation. javascript
function setup() {        // Creating Canvas size     createCanvas(600, 140);  }    function draw() {            // Set the background color      background(220);          // Initializing some values     let Value1 = true;     let Value2 = false;     let Value3 = "Geeks";     let Value4 = [12, 3.6, -9.8, true, false, "Geeks"];         // Calling to str() function.     let A = str(Value1);     let B = str(Value2);     let C = str(Value3);     let D = str(Value4);           // Set the size of text      textSize(16);            // Set the text color      fill(color('red'));          // Getting string representation     text("String representation of value 'true' is: " + A, 50, 30);     text("String representation of value 'false' is: " + B, 50, 60);     text("String representation of value 'Geeks' is: " + C, 50, 90);     text("String representation of array of values are: " + D, 50, 110); }   
Output: Reference: https://p5js.org/reference/#/p5/str

Next Article
p5.js split() function

K

Kanchan_Ray
Improve
Article Tags :
  • JavaScript
  • Web Technologies
  • JavaScript-p5.js

Similar Reads

  • p5.js trim() function
    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 para
    2 min read
  • p5.js sqrt() function
    The sqrt() function in p5.js is used to get the square root of any input number. Syntax: sqrt(n) Parameters: This function accepts single parameter n which is an input non-negative number whose square root is being calculated. Return Value: It returns the square root of any input number. Below progr
    1 min read
  • p5.js sort() function
    The sort() function in p5.js is used to sort the array elements. If the array elements are strings then it sorts them alphabetically and if the array elements are integers then it sorts them in increasing order. Syntax: sort(Array, Count) Parameters: This function accepts two parameters as mentioned
    3 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 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
  • p5.js storeItem() Function
    The storeItem() function is used to store a given value under a key name in the local storage of the browser. The local storage persists between browsing sessions and can store values even after reloading the page. It can be used to save non-sensitive information, such as user preferences. Sensitive
    2 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 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 splice() function
    The splice() function in p5.js is used to insert values or array elements in the given array.Syntax:   splice(Array, Values, Position) Parameters: This function accepts three parameters as mentioned above and described below:   Array: This is a given array which is to be modified.Values: This is the
    3 min read
  • p5.js saveStrings() Function
    The saveStrings() function is used to write an array of strings with one line per string to the file. The saving of the file will vary depending on the web browser. Syntax: saveStrings( list, filename, extension ) Parameters: This function accept three parameter as mentioned above and described belo
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences