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를 최신 버전으로 업데이트해 주세요.
LENGTH counts characters
LENGTH(s)gives how many characters are in a string.
OUTPUT LENGTH("hello") // → 5
UCASE and LCASE change case
UCASE(s)makes a string all CAPITALS.LCASE(s)makes it all lower case.
OUTPUT UCASE("abc") // → ABC
OUTPUT LCASE("HeLLo") // → hello
SUBSTRING takes part of a string
SUBSTRING(s, start, length)copies part of a string.- The first character is position 1 (not 0).
OUTPUT SUBSTRING("Computer", 1, 4) // → Comp
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.
DECLARE Lives : INTEGER
Lives ← 3
OUTPUT "Cam", "bridge" // → Cambridge
OUTPUT "You have ", Lives, " lives left"
Common mistakes
- Learn the exam's function names:
LENGTH,SUBSTRING,UCASE,LCASE. - String positions in pseudocode often start at
1, not0.
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. · 단어를 입력받아 첫 번째 3 글자를 SUBSTRING로 시작하여 (시작 위치 1, 길이 3) 출력하십시오. 입력이 Computer인 경우, 출력은 Com이어야 합니다.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.