> 
 > 
4. Blocks Coding with Web App
Text
Text

This documentation covers text manipulation, including setting, checking length, concatenation, conversion between text and numbers, substring operations, character positions, and using character codes.

Basic Text

Setting Text

String

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"text\"><field name=\"TEXT\"/></block></xml>"}

This block is used to set a letter or text inside the block. 

Parameters: String
Output: String
Sample code:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>imageModel</variable><variable>downloadImage</variable><variable>predictionResult</variable><variable>resultItems</variable><variable>layout</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><shadow type=\"text\"><field name=\"TEXT\"/></shadow><block type=\"text\"><field name=\"TEXT\">Hello</field></block></value></block></value></block></next></block></next></block></statement></block></xml>"}

The output:

String - Output

Checking the Length of Text

Length of

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"text_length\"><value name=\"VALUE\"><shadow type=\"text\"><field name=\"TEXT\">Hello</field></shadow></value></block></xml>"}

This block is used to show the number of letters in the text. 

Parameters: String
Output: Number
Sample code:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>imageModel</variable><variable>downloadImage</variable><variable>predictionResult</variable><variable>resultItems</variable><variable>layout</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><shadow type=\"text\"><field name=\"TEXT\"/></shadow><block type=\"Util_convertToText\"><value name=\"value\"><shadow type=\"math_number\" disabled=\"true\"><field name=\"NUM\">0</field></shadow><block type=\"text_length\"><value name=\"VALUE\"><shadow type=\"text\"><field name=\"TEXT\">Hello</field></shadow></value></block></value></block></value></block></value></block></next></block></next></block></statement></block></xml>"}

The output:

Length of - Output

Concatenating the Text

Join

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"text_join\"><mutation items=\"2\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">Hello</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">World</field></shadow></value></block></xml>"}

This block is used to set a piece of text by joining another text together. 

Parameters: String
Output: String
Sample code:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>imageModel</variable><variable>downloadImage</variable><variable>predictionResult</variable><variable>resultItems</variable><variable>layout</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><shadow type=\"text\"><field name=\"TEXT\"/></shadow><block type=\"text_join\"><mutation items=\"2\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">Hello</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">World</field></shadow></value></block></value></block></value></block></next></block></next></block></statement></block></xml>"}

The output:

Join - Output

Transforming Number to Text

Convert 0 to text

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Util_convertToText\"><value name=\"value\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow></value></block></xml>"}

This block is used to change the number to text. 

Parameters: Number
Output: String
Sample code:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>imageModel</variable><variable>downloadImage</variable><variable>predictionResult</variable><variable>resultItems</variable><variable>layout</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><shadow type=\"text\"><field name=\"TEXT\"/></shadow><block type=\"Util_convertToText\"><value name=\"value\"><shadow type=\"math_number\"><field name=\"NUM\">55</field></shadow></value></block></value></block></value></block></next></block></next></block></statement></block></xml>"}

The output:

Convert 0 to text - Output

Transforming Text to Number

Parse to number 123

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"string_parsefloat\"><value name=\"text\"><shadow type=\"text\"><field name=\"TEXT\">123</field></shadow></value></block></xml>"}

This block is used to convert a text to a number. 

Parameters: String
Output: Number
Sample code:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>imageModel</variable><variable>downloadImage</variable><variable>predictionResult</variable><variable>resultItems</variable><variable>layout</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><shadow type=\"text\"><field name=\"TEXT\"/></shadow><block type=\"Util_convertToText\"><value name=\"value\"><shadow type=\"math_number\"><field name=\"NUM\">55</field></shadow><block type=\"string_parsefloat\"><value name=\"text\"><shadow type=\"text\"><field name=\"TEXT\">123</field></shadow></value></block></value></block></value></block></value></block></next></block></next></block></statement></block></xml>"}

The output:

Convert 0 to text - Output

More in Text

Breaking Text with Separators

Split this at …

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"string_split\"><value name=\"this\"><shadow type=\"text\"><field name=\"TEXT\">this</field></shadow></value><value name=\"separator\"><shadow type=\"text\"><field name=\"TEXT\"/></shadow></value></block></xml>"}

This block is used to break the text according to the separators. 

Parameters: Screen Item/String
Output: String Array
Sample code:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>text</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">text</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"text\"><field name=\"TEXT\">The block is replacing space with comma.</field></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><block type=\"Util_convertToText\"><value name=\"value\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"string_split\"><value name=\"this\"><shadow type=\"text\"><field name=\"TEXT\"/></shadow><block type=\"variables_get\"><field name=\"VAR\">text</field></block></value><value name=\"separator\"><shadow type=\"text\"><field name=\"TEXT\"> </field></shadow></value></block></value></block></value></block></value></block></next></block></next></block></next></block></statement></block></xml>"}

The output:

Split this at - Output

Checking Whether the Text Contains Characters

This includes …

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"string_includes\"><value name=\"this\"><shadow type=\"text\"><field name=\"TEXT\">this</field></shadow></value><value name=\"searchValue\"><shadow type=\"text\"><field name=\"TEXT\"/></shadow></value></block></xml>"}

This block is used to check whether the text contains the characters of the text. 

Parameters: Screen Item/String
Output: Boolean (True/False)
Sample code:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>text</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">text</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"text\"><field name=\"TEXT\">Hello World</field></block></value><next><block type=\"controls_if\"><mutation else=\"1\"/><value name=\"IF0\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow><block type=\"string_includes\"><value name=\"this\"><shadow type=\"text\"><field name=\"TEXT\"/></shadow><block type=\"variables_get\"><field name=\"VAR\">text</field></block></value><value name=\"searchValue\"><shadow type=\"text\"><field name=\"TEXT\">World</field></shadow></value></block></value><statement name=\"DO0\"><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><shadow type=\"text\"><field name=\"TEXT\">World is inside the text.</field></shadow></value></block></value></block></statement><statement name=\"ELSE\"><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><shadow type=\"text\"><field name=\"TEXT\">World is not inside the text.</field></shadow></value></block></value></block></statement></block></next></block></next></block></next></block></statement></block></xml>"}

When sets it to ‘text includes World’, the output:

This includes - True Output

When sets it to ‘text includes World’, the output:

This includes - False Output

Finding the Position of the Character

This find index of …

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"string_parsefloat\"><value name=\"text\"><shadow type=\"text\"><field name=\"TEXT\">123</field></shadow></value></block></xml>"}

This block is used to find the position of the first occurrence of the value in the text. 

Parameters:  

  • String/Screen Item
  • String

Output: Number
Sample code:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>text</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">text</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"text\"><field name=\"TEXT\">Hello World</field></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><block type=\"Util_convertToText\"><value name=\"value\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"string_indexof\"><value name=\"this\"><shadow type=\"text\"><field name=\"TEXT\"/></shadow><block type=\"variables_get\"><field name=\"VAR\">text</field></block></value><value name=\"searchValue\"><shadow type=\"text\"><field name=\"TEXT\">W</field></shadow></value></block></value></block></value></block></value></block></next></block></next></block></next></block></statement></block></xml>"}

The output:

This find index of - Output

Checking Text is Empty or Not

This is empty

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"string_isempty\"><value name=\"this\"><shadow type=\"text\"><field name=\"TEXT\">this</field></shadow></value></block></xml>"}

This block is used to check whether the text is empty.

Parameters: String/Screen Item
Output: Boolean (True/False)
Sample code:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>text</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">text</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"text\"><field name=\"TEXT\"/></block></value><next><block type=\"controls_if\"><mutation else=\"1\"/><value name=\"IF0\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow><block type=\"string_isempty\"><value name=\"this\"><shadow type=\"text\"><field name=\"TEXT\"/></shadow><block type=\"variables_get\"><field name=\"VAR\">text</field></block></value></block></value><statement name=\"DO0\"><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><shadow type=\"text\"><field name=\"TEXT\">There is nothing inside.</field></shadow></value></block></value></block></statement><statement name=\"ELSE\"><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><shadow type=\"text\"><field name=\"TEXT\">There is something inside.</field></shadow></value></block></value></block></statement></block></next></block></next></block></next></block></statement></block></xml>"}

When the text is nothing inside, the output:

This is empty - True Output

When text contains string, the output:

This is empty - False Output

Showing Text in Substring Format

Substring of this from 0 of length 10

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"string_substr\"><value name=\"this\"><shadow type=\"text\"><field name=\"TEXT\">this</field></shadow></value><value name=\"start\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow></value><value name=\"length\"><shadow type=\"math_number\"><field name=\"NUM\">10</field></shadow></value></block></xml>"}

This block is used to show the substring from the selected text.

Parameters: 

  • String/Screen Item
  • Condition: Number (Default: 0 and 10)

Output: String
Sample code:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>text</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">text</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"text\"><field name=\"TEXT\">Hello World!</field></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><block type=\"string_substr\"><value name=\"this\"><shadow type=\"text\"><field name=\"TEXT\"/></shadow><block type=\"variables_get\"><field name=\"VAR\">text</field></block></value><value name=\"start\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow></value><value name=\"length\"><shadow type=\"math_number\"><field name=\"NUM\">7</field></shadow></value></block></value></block></value></block></next></block></next></block></next></block></statement></block></xml>"}

The output:

Substring of this from 0 of length 10 - Output

Showing the Order of Characters in Two Texts

Compare this to …

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"string_compare\"><value name=\"this\"><shadow type=\"text\"><field name=\"TEXT\">this</field></shadow></value><value name=\"that\"><shadow type=\"text\"><field name=\"TEXT\"/></shadow></value></block></xml>"}

This block is used to show the order of characters in two texts is different. 

Parameters: String/Screen Item
Output: Number
Sample code:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><block type=\"Util_convertToText\"><value name=\"value\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"string_compare\"><value name=\"this\"><shadow type=\"text\"><field name=\"TEXT\">Hello World!</field></shadow></value><value name=\"that\"><shadow type=\"text\"><field name=\"TEXT\">Hello</field></shadow></value></block></value></block></value></block></value></block></next></block></next></block></statement></block></xml>"}

The output:

Compare this to - Output

Displaying Character at the Certain Position

Char from this at 0

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"string_get\"><value name=\"this\"><shadow type=\"text\"><field name=\"TEXT\">this</field></shadow></value><value name=\"pos\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow></value></block></xml>"}

This block is used to show the character at the specified position. 

Parameters: String/Screen Item
Output: Number
Sample code:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><block type=\"string_get\"><value name=\"this\"><shadow type=\"text\"><field name=\"TEXT\">this</field></shadow></value><value name=\"pos\"><shadow type=\"math_number\"><field name=\"NUM\">3</field></shadow></value></block></value></block></value></block></next></block></next></block></statement></block></xml>"}

The output:

Char from this at - Output

Using Character Code to Show Text

Text from char code 0

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"stringFromCharCode\"><value name=\"code\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow></value></block></xml>"}

This block is used to show the character using the ASCII code. 

Parameters: Number
Output: String
Sample code:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><block type=\"stringFromCharCode\"><value name=\"code\"><shadow type=\"math_number\"><field name=\"NUM\">101</field></shadow></value></block></value></block></value></block></next></block></next></block></statement></block></xml>"}

The output:

Char from this at - Output

Table of Content