1.7 KiB
String
a piece of text.
@parent blocks/language
A String is a sequence of characters. For the BBC micro:bit, ASCII character codes 32 to 126 are supported; letters, digits, punctuation marks, and a few symbols. All other character codes appear as a ? on the LED screen.
Declare a string
Use the var statement and the assignment operator to declare a new local string variable. Like this:
To declare a string using the Block Editor:
-
Click
Variables
(as the Block drawer). -
Type a name for your new string variable by clicking the down arrow, then click New Variable. Then type the variable name "salutation"
-
Drag a string block on the right side of the operator.
-
Click
"Hello"
and then type a string likehello
.
Your code should look something like this:
The function show string
Use show string to display a string on the LED screen. If the string is multiple characters, the string scrolls right to left. The following example displays Hello world!
on the micro:bit screen:
The parameter of show string
specifies the string
Lessons
glowing pendulum, zoomer, temperature