The result of two strings being joined together with the (join [] []) block.
Strings are sequences of binary-encoded computer characters, including spaces. More commonly known as letters and numbers, they can be of any length, though in certain circumstances they are limited to 10,240 characters,[1] may include any typable character, and can be put to work in certain blocks, mostly found in the Operators section. String support was added in Scratch 1.4.[2]

Example Strings

Below are some examples that express the theoretically infinite range of strings.

  • A string
say [Hello world!]
  • Addressing a user by their username
when gf clicked
say (join (join [Hi, ] (username)) [!])
  • A string with a variable inside
when gf clicked
if <(score) < (3)> then
say (join (join [Your score was ] (score)) [. Better luck next time!])
else
say (join (join [Your score was ] (score)) [! Keep it up!])
  • The empty string or null string is a string with no characters
set [test v] to [] // Empty
set [test v] to (join (test) [a]) // Now test is "a"

Blocks that can Handle Strings

Several blocks use strings; below is a full list. Click on a block to learn more about it.

Reporter Blocks Involving Strings

Stack Blocks Involving Strings

String or Number?

In Scratch, strings are casted into 0 when put into a number slot. This can only be done by using the (variable), (answer), or (item ( v) of [ v]) blocks. However, sometimes a string is not wanted in a number insert, such as in an OS clock. This is a simple script that detects whether or not something is a string or a number:

if <<((reporter) + (1)) = [1]> and <not <(reporter) = [0]>>> then//Strings have a reporter value of 0
say [String!]
else
say [Number!]
end

Alternatively, in BYOB, the block <is [] a [number/text]?> can be used.

Technicality

All data a computer reads is encoded into binary code, or a series of "1"s and "0"s. Each individual "1" or "0" is called a bit and 8 of these make up a byte. Different sequences of bits and bytes resemble codes for different standardized letters. This is known as an encoding, or the uniform way of breaking down letters into sequences of numbers. Different encodings use different amounts of bits for each letter, and it all depends on how many characters would be available for a single, uniform encoding.

In Scratch, a string is simply a series of encoded letters that is parsed with a particular decoder. A string of text is read by the computer as plain text as opposed to compiled code for the instructions to a central processing unit.

Character Limit

Although the maximum length of a string is not known, it is noteworthy that strings are limited in length when using the (join [] []) block, which can return a string with at most 10240 characters. This is a feature only of the join block — strings can be longer than 100 million characters if need be. The actual limit is not yet known, but is likely only limited by the memory space of the running computer.

See Also

References

  1. https://scratch.mit.edu/projects/24934494/
  2. http://info.scratch.mit.edu/Scratch_1.4_Release_Notes