ScratchData LogoScratchData
Back to PullJosh_Test's profile

Replace Letter in String

PUPullJosh_Test•Created July 6, 2019
Replace Letter in String
6
3
126 views
View on Scratch

Instructions

Here's a general solution to the question "How do I replace one letter in a string?", asked by @VinCrafts here: https://scratch.mit.edu/projects/319930551/#comments-114633655 This solution is about as clean as it gets in Scratch. What we really want is the ability to create a custom reporter block that returns a value, like we can in Snap! https://snap.berkeley.edu/site/ Instead, we have to resort to setting the value of a "result" variable and relying on that to pass back the new value. The block works by stepping through the letters in the string one at a time, keeping track of its location in the string using the "current position" variable. In most cases, it just copies the letter from the original string over to the result string. Only when the "current position" hits the spot in the string that you want to change does it insert the replacement character instead.

Project Details

Project ID319994322
CreatedJuly 6, 2019
Last ModifiedJuly 6, 2019
SharedJuly 6, 2019
Visibilityvisible
CommentsAllowed