Built-in functions from the insert · 插页上的内置函数
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · 此页面需较新浏览器(支持 SharedArrayBuffer)。请升级 Chrome、Edge、Firefox 或 Safari 至最新版本。
English
A receipt joins a number to text
- Every Paper 2 has an insert of built-in functions. Anything not in the pseudocode guide is printed there, and an answer may call it.
LEFT(Text, N)copies the firstNcharacters. Positions still start at 1.NUM_TO_STR(87.5)is the string"87.5". Join it with&when the line must contain words and a number.
中文
收据要把数字接上文字
- 每份 Paper 2 都有一张内置函数插页。伪代码指南里没有的函数印在那里,答案可以调用它。
LEFT(Text, N)复制前N个字符。位置仍然从 1 开始。NUM_TO_STR(87.5)是字符串"87.5"。一行里既要文字又要数字时,用&接上它。
OUTPUT LEFT("Computer", 3)
OUTPUT "Score: " & NUM_TO_STR(87.5)
English
Check before you convert
IS_NUM(Text)isTRUEonly when the string is a number."12a"isFALSE.STR_TO_NUM("23")is the number23, so you can add 1 to it. A string cannot be added.- Convert only after
IS_NUMsays the text is safe.
中文
先检查,再转换
- 只有字符串是一个数时,
IS_NUM(Text)才为TRUE。"12a"是FALSE。 STR_TO_NUM("23")是数字23,所以可以再加 1。字符串不能相加。- 只有
IS_NUM说这段文字安全之后,才去转换。
DECLARE Text : STRING
Text ← "23"
IF IS_NUM(Text) THEN
OUTPUT STR_TO_NUM(Text) + 1
ELSE
OUTPUT "bad"
ENDIF
English
ASC and CHR
ASC("A")is the integer code65.CHR(66)is the character"B".- The next letter after
"A"isCHR(ASC("A") + 1).
中文
ASC 与 CHR
ASC("A")是整数编码65。CHR(66)是字符"B"。"A"的下一个字母是CHR(ASC("A") + 1)。
OUTPUT CHR(ASC("A") + 1)
OUTPUT IS_NUM("12a")
English
Common mistakes
UCASEstill takes one character. A whole string in capitals isTO_UPPER, which you met earlier.NUM_TO_STRreturns text.STR_TO_NUMreturns a number. They are not interchangeable.
中文
常见错误
UCASE仍然只接受一个字符。整串大写用TO_UPPER,前面的课里见过。NUM_TO_STR返回文字。STR_TO_NUM返回数字。两者不能互换。
English
Now you try
- Use
LEFT, then a joined number, thenIS_NUMbefore a conversion.
中文
现在你来试
- 先用
LEFT,再把一个数字接进句子,最后在转换之前用IS_NUM。
Output · 输出 LEFT("Computer", 3). · 输出 LEFT("Computer", 3)。
Click Run to see the output here. · 点击“运行”查看此处输出。
Output · 输出 Score: 87.5 on one line by joining the word and NUM_TO_STR(87.5) with &. · 用 & 把文字和 NUM_TO_STR(87.5) 接成一行 Score: 87.5。
Click Run to see the output here. · 点击“运行”查看此处输出。
Text is "23". If IS_NUM(Text), output STR_TO_NUM(Text) + 1. Otherwise output bad. · Text 是 "23"。若 IS_NUM(Text),输出 STR_TO_NUM(Text) + 1。否则输出 bad。
Click Run to see the output here. · 点击“运行”查看此处输出。