String handling · 字符串处理
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
LENGTH counts characters
LENGTH(s)gives how many characters are in a string.
中文
LENGTH 数字符个数
LENGTH(s)给出字符串里有多少个字符。
OUTPUT LENGTH("hello") // → 5
English
UCASE and LCASE change case
UCASE(s)makes a string all CAPITALS.LCASE(s)makes it all lower case.
中文
UCASE 与 LCASE 改变大小写
UCASE(s)把字符串变成全大写。LCASE(s)把它变成全小写。
OUTPUT UCASE("abc") // → ABC
OUTPUT LCASE("HeLLo") // → hello
English
SUBSTRING takes part of a string
SUBSTRING(s, start, length)copies part of a string.- The first character is position 1 (not 0).
中文
SUBSTRING 取出字符串的一部分
SUBSTRING(s, start, length)复制字符串的一部分。- 第一个字符的位置是 1(不是 0)。
OUTPUT SUBSTRING("Computer", 1, 4) // → Comp
English
Printing several values
OUTPUTtakes several values separated by commas and prints them one after another.- The 0478 pseudocode has no "join" operator — a comma is how you put values side by side.
中文
一次输出多个值
OUTPUT可以用逗号分隔多个值,依次打印出来。- 0478 伪代码没有"拼接"运算符——逗号就是把多个值并排输出的方式。
DECLARE Lives : INTEGER
Lives ← 3
OUTPUT "Cam", "bridge" // → Cambridge
OUTPUT "You have ", Lives, " lives left"
English
Common mistakes
- Learn the exam's function names:
LENGTH,SUBSTRING,UCASE,LCASE. - String positions in pseudocode often start at
1, not0.
中文
常见错误
- 记住考试的函数名:
LENGTH、SUBSTRING、UCASE、LCASE。 - 伪代码中字符串位置常从
1开始,而不是0。
English
Now you try
- Use the string functions above.
- Press Check answer to test it.
中文
现在轮到你
- 使用上面的字符串函数。
- 按检查答案来测试它。
Read a word, then output how many characters it has with LENGTH. For input hello, output 5. · 读取一个单词,然后用 LENGTH 输出它有多少个字符。当输入为 hello 时,输出 5。
Click Run to see the output here. · 点击“运行”查看此处输出。
Read a word and output it in CAPITALS with UCASE. For input cat, output CAT. · 读取一个单词,用 UCASE 把它转成大写后输出。当输入为 cat 时,输出 CAT。
Click Run to see the output here. · 点击“运行”查看此处输出。
Read a word and output its first 3 letters with SUBSTRING (start at 1, length 3). For input Computer, output Com. · 读取一个单词,用 SUBSTRING(从 1 开始,长度 3)输出它的前 3 个字母。当输入为 Computer 时,输出 Com。
Click Run to see the output here. · 点击“运行”查看此处输出。