- "Length of () (block)" redirects here. For the List block, see Length of () (List block).
字串長度\( (詢問的答案) \)
|Note:||Spaces count as characters in strings.|
In certain 专案, different events can happen based on the length of a value; this block is used to help.
Some common uses for the Length of () block:
- Checking the length of a name
詢問 [What's your name?] 並等待 說出 (字串組合 (詢問的答案) 和 (字串長度\( (詢問的答案) \))) (2) 秒
- Checking how many digits there are in a player's score
重複無限次 說出 (字串長度\( (score1) \)) end
- Chatbots, where different messages can occur depending on the length of the message that was inputted
如果 <(字串長度\( (詢問的答案) \)) < (10)> 那麼 說出 [Hi!] 否則 說出 [Bye!] end
- Main article: List of Block Workarounds
This block can be replicated with the following code:
變數 [length v] 設為  重複直到 <(字串中第 ((length) + (1)) 字\( (thing) \)) = > 變數 [length v] 改變 (1) end
It can be flawed because it can be long and slow. This is also a problem:
變數 [repcount v] 設為 (0) 重複直到 <(字串中第 ((repcount) + (1)) 字\( (string) \)) = > 新增項目 (字串中第 ((repcount) + (1)) 字\( (string) \)) \( [results v] \) 變數 [repcount v] 改變 (1) end 變數 [length v] 設為 (清單 [results v] 的項目數 :: list)
It takes up lots of memory and can be slow. However, both values can be saved for later.