splitTokens not working with multiple symbols

Hi All,

Quick question about splitTokens.

function setup(){

var s = "sldfkjalfkgh,df.  sdkfj !";
var words = splitTokens(s, " ,");
console.log(words);

}

this returns the original string. Any ideas?

Thanks

Answers

  • edited May 2015

    It's indeed bugged b/c in "Java Mode" it does work: >:/

    String s = "sldfkjalfkgh,df.  sdkfj !";
    String[] words = splitTokens(s, " ,");
    
    printArray(words);
    exit();
    

    File an issue for it here: https://github.com/processing/p5.js/issues
    And post the link for this post there too for cross-reference! Good luck! :-bd

  • For questions like this, it's best to use JSFiddle. Here's one: https://jsfiddle.net/gvfc5u2x/

    This is not a bug. Run the above JSFiddle and you'll see this output:

    Array [ "sldfkjalfkgh", "df.", "sdkfj", "!" ]
    

    So you see that your code is working. It's unclear what you mean by "this returns the original String" since you aren't returning anything.

    Please modify the existing JSFiddle, or post an MCVE that demonstrates exactly what you're doing.

  • Sorry, I didn't say this clearly. I'm having issue with P5.JS not in processing JS.

  • You could just use the native JavaScript split method...

    There seem to be a lot of p5 methods which I assume just hook into the native JS equivalent. I'm inclined to favour the native method...

  • yeah, that's a good point. That's what I'm using right now.

  • You could just use the native JavaScript split() method...

    That doesn't fix the bug present in p5*js's implementation for splitTokens()! [-(

  • @GoToLoop: true, but I do wonder whether p5js even needs implementations of some of the native JavaScript methods. I understand the desire to keep a syntax consistent with Processing - so splitTokens() sort of makes sense and should be fixed...

    But there seems little point for implementations of the various Math functions... Presumably p5.abs() just returns the value of Math.abs(); which looks like an unnecessary extra function call to me. Probably not a significant performance hit; but a hit nonetheless ;)

  • edited May 2015

    ... whether p5*js even needs implementations of some of the native JavaScript methods.

    Replace "p5*js" w/ "Java Mode" & "JavaScript" w/ "Java" and you'll realize that the same can be said to Processing as a multi-programming language framework!

    Just a quick look at https://processing.org/reference/ and it's easy to conclude that about a third of it already exists in the Java's API!

Sign In or Register to comment.