(@1234abcdcda4321: I'll make yours the main one since it is shorter)
Line 40: Line 40:
 
In [[Scratch]], strings are [[Casting|casted]] into 0 when put into a number slot. This can only be done by using the [[() (Variable block)|variable]], [[Answer (block)|answer]], or [[Item () of () (block)|item () of ()]] 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:
 
In [[Scratch]], strings are [[Casting|casted]] into 0 when put into a number slot. This can only be done by using the [[() (Variable block)|variable]], [[Answer (block)|answer]], or [[Item () of () (block)|item () of ()]] 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:
  
<scratchblocks>if <<not <(testing) = [0]>> and <((testing) + (1)) = [1]>> then
+
<scratchblocks>
    set [output v] to [string]
+
if <((string) * (1)) = (string)>
 +
set [output v] to [number v]
 
else
 
else
    set [output v] to [number]
+
set [output v] to [string v]
end</scratchblocks>
+
end
Or, you could try
+
</scratchblocks>
<scratchblocks><((test) * (1)) = (test)></scratchblocks>
 
 
 
 
Alternatively, in [[BYOB]], the block <is [] a [number/text]?> can be used.
 
Alternatively, in [[BYOB]], the block <is [] a [number/text]?> can be used.
  

Revision as of 23:46, 7 February 2014

The result of two strings being joined together with the Join ()() block.
Strings are series of keyboard characters.[1] They can be of any length, include any typable character, and 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
  • A string with a "quote" inside
  • Addressing a user by his or her username
when gf clicked
say (join (join [Hi, ] (username)) [!])

Blocks that can Handle Strings

Several blocks use strings; below is a full list:

String Reporters

Certain blocks can make use of strings, forming new ones or reading aspects of them, such as its character length.

  • Join ()(): Joins two strings together with no space in between (to connect words, one can add spaces at the end of or the beginning of one of the strings)
  • Letter () of (): Reports the numbered character of a given string
  • Length of (): Reports the length of a given string
  • Answer: Reports the string input requested from the Ask () and Wait block
  • (variable):reports the string or value stored within a variable
  • (list):reports a string consisting of all items of a list combined in numerical order

String Inserts

Other blocks take string input and keep it.

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 () 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 <((string) * (1)) = (string)>
set [output v] to [number v]
else
set [output v] to [string v]
end

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

References

  1. Wikipedia:String (computer science)
  2. http://info.scratch.mit.edu/Scratch_1.4_Release_Notes