Working with strings can be difficult with limited options, but there are almost always workarounds. In a string, an individual character can be changed. This tutorial explains the concept of changing one character to another. The scripts below are custom blocks that are easier to work with. There are two basic methods for performing this: the Variable Method and List Method.
Note: | The scripts below should be run without screen refresh, which can be found in the custom block's edit menu, so it generates instantly |
Note: | For these two methods, the custom block input (string) must have the variable itself dragged into it for this to work, instead of the name of typing the variable in, because then the name itself is rendered as the string instead of the variable's characters |
Programming
Variables Method
In this method, assume the following:
(changer)
is the variable used to work with the transition of the character to the desired one(item#)
is the variable used to iterate through the string(string)
is the text that describes what variable will be changed
define change (character#) of string to (new character) set [changer v] to [] //This is blank set [item# v] to (0) //So the string transfer begins at the beginning of the string repeat ((character#) - (1)) //Repeats the amount of characters before the one going to be changed change [item# v] by (1) //Moves on to the next character set [changer v] to (join (changer) (letter (item#) of (string))) //Adds the current character to "changer" end set [changer v] to (join (changer) (new character)) //Adds the new character that replaces the old one set [item# v] to (character#) //Sets "item#" to the changed character repeat ((length of (string)) - (character#)) //Repeats the amount of characters after the changed one change [item# v] by (1) //Moves on to the next character set [changer v] to (join (changer) (letter (item#) of (string))) //Adds the current character to "changer" end set [string v] to (changer) //Stores the new string in the specified variable change (3) of string to [h] //This is what the custom block looks like
List Method
For this method, assume the following:
(item#)
is the variable used to iterate through the string(letters:: list)
is the list which separates each letter of the string and modify it(string)
is the string input in the custom block that represents what the character will be changed to
define change (character#) of string to (new character) //"string" is a string input that represents the original text before the character change delete all of [letters v] //Clears the list of letters set [item# v] to (0) //So the transferring of the variable's letters to the list starts at the beginning of the string repeat (length of (string)) //Repeats the amount of characters there are in the variable represented by the input (string) change [item# v] by (1) //Moves on to the next letter add (letter (item#) of (string)) to [letters v] //Adds the current letter as a new item to the list end replace item (character#) of [letters v] with (new character) //Replaces the specified character with the new one set [string v] to (letters) //The variable is then set to the list of letters. (letters) is a combination of each letter of the list in own string change (3) of string to [h] //This is what the custom block looks like