jump to navigation

strlen(yarn) October 16, 2009

Posted by Andor Salga in Open Source, Processing.js.

I was working on implementing my splice() function and realized the equals() method for the String class in the Procesing.js library was missing. I really needed it because after I splice a bunch of arrays of strings, I need to make sure my function did it properly. I first looked at trying to write the JavaScript in the Processing.js library. After I realized I had absolutely no idea where to place it, I brainstormed on a way to do it in the Processing.js code. This is what I came up with:

boolean stringsEqual(String str1, String str2)
 if(str1.length() != str2.length())return false;
 for(int i = 0; i < str1.length(); i++)
  char ai = str1[i];
  char bi = str2[i];
  if( ai != bi )
   return false;
 return true;

This first time around I tried casting to ints. That didn’t work, so I tried chars. So far it looks like it’s working! Feel free to offer suggestions or use this in your code!


1. Tom Higgins - November 7, 2009


Thanks for this! It works fine. Also, if it hadn’t been for this blog I would still be thinking it was my fault I couldn’t write mystring.equals(“name”) in Processing.js. I’ve got to keep in mind that the whole thing is a bit developmental. Odd bits are missing here and there. Still, it’s a great idea and holds a lot of promise.

I doubt your algorithm could be much improved.

2. asalga - November 7, 2009

Glad it was useful to you! It’s funny you mention about the development issue. Working on a language that’s still in the works definitely changes how I feel about bugs. I’m never sure if I should be glad I found a bug in the language or I upset because it just took me an hour to figure out my code is fine.

3. Thomas B. Higgins - November 10, 2009

I would say, feel really happy when you’ve found a bug during development. The earlier the better!

You might want to see my remarks here: http://stackoverflow.com/questions/856947/has-anyone-got-processing-js-working-in-ie.

Do you know anything definite about fonts for the Glyph Method?

4. Thomas B. Higgins - February 25, 2011


I’ve been porting my Processing.js code to Processing. Processing 1.2.1 has very strict syntax checking. It’s Java 6, I believe. I found I had to convert these lines:

char ai = str1[i];
char bi = str2[i];


char ai = str1.charAt(i);
char bi = str2.charAt(i);

Of course, at this point I believe the equals() method has been implemented in Processing.js, so I should convert to its use in both environments.

How are things with you?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

%d bloggers like this: