From Test-Scratch-Wiki

字串中第 () 字 ()
字串中第 (1) 字\( (詢問的答案) \)
类别 运算类积木
形狀 椭圆形积木
加入於 1.4

The Letter () of () 积木 is an 运算类积木 and a 椭圆形积木. The block reports the specified character of the given text. Even though the block says "letter", it will report all characters, including letters, numbers, symbols, and even spaces.

用法示例

If a value must be read out from the middle of a text, this block will do the job.

Some common uses for the Letter () of () block:

  • In conjunction with the 询问的答案 block to find something out about the answer
如果 <(字串中第 (1) 字\( (詢問的答案) \)) = [z]> 那麼 
  說出 [That's my favorite letter too!] (3) 秒

  說出 [Interesting.] (2) 秒
end
  • To find a number in the middle of a 字串 of text
如果 <清單 [numbers v] 包含 (字串中第 (n) 字\( (詢問的答案) \)) ?> 那麼 
  說出 [Number]
否則
  說出 [Letter/punctuation]
end
  • To tell whether a certain letter in a string equals a certain value
如果 <(letter (testing) of (詢問的答案)) = [z]> 那麼 
  停止 [這個程式 v]
end

Variations

Some Scratch 修改版 have a block that lets users choose how many characters in a string to report. This is also wanted for Scratch.[1] It would be like this: (letters () through () of [])//category=operators

However, it can be replicated with the following code:

變數 [report v] 設為 []
變數 [count v] 設為 (first letter)
重複直到 <(count) = ((last letter) + (1))> 
  變數 [report v] 設為 (字串組合 (report) 和 (字串中第 (count) 字\( (text) \)))
  變數 [count v] 改變 (1)
end

参见

— the version for 清单s

参考

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