(Redirected from Text/Number Sensors)

The result of two strings being joined together with the (join [] []) block.

A string is a sequence of computer characters, including spaces. They can be of any length, may include any character, and can be used in certain blocks, mainly found in the Operators section.

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 green flag 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

Boolean 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 () 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

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 known as a bit and 8 of these create 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

Note Warning: Strings that are very long may result in crashing Scratch.

A string can be of any length; and strings can be longer than 100 million characters if need be. The length is only limited by the memory space of the running computer.

See Also

References

Cookies help us deliver our services. By using our services, you agree to our use of cookies.