文本
該文件涵蓋了文本處理,包括設置、檢查長度、連接、文本與數字之間的轉換、子字串操作、字符位置以及使用字符代碼。
基本文本
設置文字
字串
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"text\"><field name=\"TEXT\"/></block></xml>"}
此塊用於在塊內設置字母或文本。
參數: String (字串)
輸出: 字串
示例代碼:
{"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>"}
輸出:
檢查文本的長度
長度
{"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>"}
此塊用於顯示文字中的字母數。
參數: String (字串)
輸出: 數位
示例代碼:
{"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>"}
輸出:
連接文字
加入
{"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>"}
此塊用於通過將另一個文本連接在一起來設置一段文本。
參數: String (字串)
輸出: 字串
示例代碼:
{"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>"}
輸出:
將數字轉換為文字
將 0 轉換為文字
{"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>"}
此塊用於將數位更改為文字。
參數: 數
輸出: 字串
示例代碼:
{"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>"}
輸出:
將文字轉換為數位
解析到數位 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>"}
此塊用於將文字轉換為數位。
參數: String (字串)
輸出: 數位
示例代碼:
{"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>"}
輸出:
更多文字內容
使用分隔符分隔文字
將其拆分為…
{"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>"}
此塊用於根據分隔符分隔文本。
參數: 屏幕專案/字串
輸出: 字串數位語式組
示例代碼:
{"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>"}
輸出:
檢查文字是否包含字元
這包括……
{"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>"}
此塊用於檢查文本是否包含文字的字元。
參數: 屏幕專案/字串
輸出: 布爾值(True/False)
示例代碼:
{"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>"}
當將其設置為「text includes World」時,輸出:
當將其設置為「text includes World」時,輸出:
查找字元的位置
這個發現索引…
{"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>"}
此塊用於查找值在文本中首次出現的位置。
參數:
- 字串/螢幕項
- 字串
輸出: 數位
示例代碼:
{"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>"}
輸出:
檢查文本是否為空
這是空的
{"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>"}
此塊用於檢查文本是否為空。
參數: 字串/螢幕項
輸出: 布爾值(True/False)
示例代碼:
{"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>"}
當文字內部沒有任何內容時,輸出:
當文字包含字串時,輸出:
以子字串格式顯示文字
this 的子字串,從 0 到長度 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>"}
此塊用於顯示所選取文字中的子字串。
參數:
- 字串/螢幕項
- 條件: 數字(預設值:0 和 10)
輸出: 字串
示例代碼:
{"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>"}
輸出:
顯示兩個文字中的字元順序
將此與…進行比較
{"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>"}
此塊用於顯示兩個文字中字元的順序不同。
參數: 字串/螢幕項
輸出: 數位
示例代碼:
{"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>"}
輸出:
在特定位置顯示字元
從 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>"}
這個塊用於在指定位置顯示字元。
參數: 字串/螢幕項
輸出: 數位
示例代碼:
{"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>"}
輸出:
使用字元代碼顯示文字
來自字元代碼 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>"}
這個塊用於使用 ASCII 代碼顯示字元。
參數: 數
輸出: 字串
示例代碼:
{"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>"}
輸出:
目録