1.5: JavaScript String Object – Programming with Text

[ad_1]
In this video, I discuss the JavaScript String object, and how to use it to modify and manipulate text in JavaScript. The functions / properties covered are indexOf(), substring(), and length. I look at the p5.js specific split(), splitTokens(), and join().

Next Video:

Introduction to Programming from A to Z:

Support this channel on Patreon:

Send me your questions and coding challenges!:

Contact:

GitHub Repo with all the info for Programming from A to Z:

Source Code for the all Video Lessons:

MDN JavaScript String Object reference:

p5.js:
Processing:

For More Programming from A to Z videos:

For More Coding Challenges:

Help us caption & translate this video!


Posted

in

by

Tags:

Comments

8 responses to “1.5: JavaScript String Object – Programming with Text”

  1. P-YAN Avatar

    As a complete newbie, when you skip showing the first Index.html code to make your text appear after pressing the button, I cannot check what I have done wrong because mine doesn't work and therefore are unable to follow along after that.

  2. Darren King Avatar

    Great stuff! One thought: "let" is your friend! 😉

  3. Bartek Jajkowski Avatar

    Ok, so my solution for your challenge is:
    var textfield;
    var button;
    var output;

    function setup() {
    noCanvas();
    textfield = select("#textfield");
    button = select("#button");
    output = select("#output");
    button.mousePressed(countText);
    }

    function countText() {
    var s = textfield.value();
    var o = 0;
    for (var i = 0; i < s.length; i++) {
    var index = s.indexOf("rainbow", i);
    if (index > o) {
    createP(index);
    o = index;
    }
    }
    }

    Is there better solution?
    Cheers

  4. Mikael H Avatar

    Im getting an error Uncaught TypeError: Cannot read property 'value' of null
    at p5.Element.newText (sketch.js:16)
    The error is in this line..
    var s = textfield.value();

  5. Daniel Mogin Avatar

    Why are you always using the P5 library ?

  6. LupusCogitabundus Cogitabundus Avatar

    Good that Java and Javascript are similar 😀 thank you for this Video

Leave a Reply

Your email address will not be published. Required fields are marked *