String handling
Cambridge Pseudocode Lesson 9 2:07 English narration · English + 中文 subtitles burned in
Chapters
Transcript
Three of the string functions have nothing to trip on.
有三个字符串函数没有什么坑。
LENGTH gives how many characters are in a string — hello is five.
LENGTH 给出一个字符串里有多少个字符——"hello" 是 5。
UCASE returns it in capitals, and LCASE in lower case.
UCASE 把它变成大写返回,LCASE 变成小写。
Neither changes the original; both hand back a new string.
两者都不改变原来的字符串;它们都交回一个新的字符串。
The only thing to get right is the exam's own names for them.
唯一需要弄对的,是考卷给它们起的那些名字。
Now the thing that costs marks, and it is not a function name.
现在说那个会丢分的东西,而它不是某个函数名。
In Cambridge pseudocode the C is position one.
在剑桥伪代码里,这个 C 是位置 1。
In Python, on the very same boxes, the same C is zero.
在 Python 里,在完全同样的这些格子上,同一个 C 是 0。
If you have been writing Python all term, your hand will reach for nought without asking you.
如果你整个学期都在写 Python,你的手会不问你就伸向 0。
Look at the two rows of numbers and remember that the top one is the one the paper wants.
看这两排数字,记住上面那一排才是考卷要的。
SUBSTRING copies part of a string, and it takes three things: the string, where to start, and how many characters to take.
SUBSTRING 复制一个字符串的一部分,它需要三样东西: 这个字符串、从哪里开始、以及要取多少个字符。
Four characters starting at one covers C, o, m, p — so it gives you Comp.
从 1 开始取 4 个字符,覆盖 C、o、m、p——所以它给你 "Comp"。
And read that third number carefully: it is how many to take, not where to stop.
再仔细读那第三个数字: 它是"取多少个",不是"到哪里停"。
Confusing those two is the other half of the marks lost on this topic.
把这两者搞混,是这个知识点上丢掉的另一半分数。
Last one.
最后一个。
The ampersand joins two strings end to end — Cam and bridge become Cambridge.
& 把两个字符串首尾接起来——"Cam" 和 "bridge" 变成 "Cambridge"。
It adds nothing of its own, so if you want a space between two words you have to join one in yourself, as a string of one space.
它自己不添加任何东西, 所以如果你想在两个词之间要一个空格,你得自己把它接进去, 作为一个只有一个空格的字符串。
That is why the second line has three pieces instead of two.
这就是为什么第二行有三段而不是两段。
Four things to take with you.
带走四点。
One: LENGTH counts characters, and UCASE and LCASE change case.
第一:LENGTH 数字符个数,UCASE 和 LCASE 改变大小写。
Two: the first character is at position 1, not 0.
第二:第一个字符在位置 1,不是 0。
Three: SUBSTRING takes a start and how many to copy.
第三:SUBSTRING 需要一个起点和"取多少个"。
Four: the ampersand joins strings and adds no space of its own.
第四:& 把字符串接起来,自己不添加空格。
Now do the three tasks.
现在去做那三道题。