Letter () of () | |
letter () of () | |
Category | Operators |
Type | Reporter |
Introduced in | 1.4 |
The Letter () of () block is an Operators block and a Reporter block. The block reports the specified character of the given text. Even though the block says "letter", it will report all characters, including letters, numbers, symbols, and even spaces. The block is also useful to write the time, show scores in games, generating project save codes, and decoding certain scripts.
Example Uses
If a value must be read out from the middle of a text, this block will do the job.
Some common uses for the Letter () of () block:
- In conjunction with the answer block to find something out about the answer
if <(letter (1) of (answer)) = [z]> then say [That's my favorite letter too!] for (3) secs else say [Interesting.] for (2) secs end
- To find a number in the middle of a string of text
if <(numbers) contains (letter (n) of (answer))?> then say [Number] else say [Letter/punctuation] end
- To tell whether a certain letter in a string equals a certain value
if <(letter (testing) of (answer)) = [z]> then stop [this script v] end
- To tell a specific letter in a username
If <(letter (1) of (username)) = [a]> then say [The first letter of your username is a.]
- To detect a key that is not in the drop-down menu of the Key () Pressed? block
if <key (letter (1) of [.]) pressed?> then set [answer v] to (join (answer) [.]) end
Variations
Some Scratch Modifications have a block that lets users choose how many characters in a string to report. This is also wanted for Scratch.[1] It would be like this: (letters () through () of []::operators)
However, it can be replicated with the following code:
set [result v] to [] set [counter v] to (first letter) repeat (((last letter)-(first letter))+(1)) set [result v] to (join (result) (letter (counter) of (string))) change [counter v] by (1) end
See Also
- Item () of () — a similar block, used for lists
References
() + () • () - () • () * () • () / () • Pick Random () to () • () < () • () = () • () > () • () and () • () or () • Not () • Join ()() • Letter () of () • Length of () • () Mod () • Round () • () of ()More blocks...
|