Skip to content

String methods in Scratch BYOB

Each of the last 3 years we’ve been able to get more and more out of Scratch as it went from 1.2 to 1.4, and especially now with the BYOB 3 version from Berkeley. Adding in the ability to have students build their own methods in Scratch means that we could do a pretty decent job teaching our intro CompSci class with just Scratch. We don’t, mostly because it’s important to expose them to more than one language as part of their intro to computer science so we go from Scratch to Alice to Python and finally to Java. But we could. The time we spend in Scratch is time very well spent as the students are able to tie concepts back to Scratch once we get into languages where the concept of a loop isn’t quite so visual.

Some of the most difficult labs that we come to are string labs, mostly because up until version 1.4 Scratch didn’t directly support Strings and Alice doesn’t handle them very well. So the first time we deal with concepts like sub strings is Python.

I’m hoping the following 3 blocks that I put together today will allow us to teach the idea of Strings in a little more visual way and when we get to Python and Java we just have to teach the methods, not the concepts.

letters x to y in z works the same way as substring in Java, with the exception that lists and Strings in Scratch are 1 based instead of 0 based.

findFirst and findLast work like the Java indexOf and lastIndexOf methods and both call on the letters block above.

I tested these out pretty quickly, but I’m sure if there are problems my kids will find ’em and mock me accordingly.

Published inComputer Science

Be First to Comment

Leave a Reply

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