String handling · Manipulação de strings
LENGTH counts characters
LENGTH(s)gives how many characters are in a string.
LENGTH conta caracteres
LENGTH(s)retorna quantos caracteres estão em uma string.
OUTPUT LENGTH("hello") // → 5
UCASE and LCASE change case
UCASE(s)makes a string all CAPITALS.LCASE(s)makes it all lower case.
UCASE e LCASE alteram o caso
UCASE(s)transforma uma string toda em MAIÚSCULAS.LCASE(s)transforma tudo em minúsculas.
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).
SUBSTRING extrai parte de uma string
SUBSTRING(s, start, length)copia parte de uma string.- O primeiro caractere está na posição 1 (não 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.
Imprimir vários valores
OUTPUTaceita vários valores separados por vírgulas e os imprime um após o outro.- O pseudocódigo 0478 não tem operador de 'junção' — uma vírgula é como você coloca valores lado a lado.
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.
Erros comuns
- Aprenda os nomes das funções da prova:
LENGTH,SUBSTRING,UCASE,LCASE. - As posições de string no pseudocódigo muitas vezes começam em
1, não em0.
Now you try
- Use the string functions above.
- Press Check answer to test it.
Agora você tenta
- Use as funções de string acima.
- Pressione Check answer para testá-lo.
Read a word, then output how many characters it has with LENGTH. For input hello, output 5. · Leia uma palavra, depois saia com quantos caracteres ela tem usando LENGTH. Para entrada hello, saia com 5.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.
Read a word and output it in CAPITALS with UCASE. For input cat, output CAT. · Leia uma palavra e saia com ela em MAIÚSCULAS usando UCASE. Para entrada cat, saia com CAT.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.
Read a word and output its first 3 letters with SUBSTRING (start at 1, length 3). For input Computer, output Com. · Leia uma palavra e saia com suas 3 primeiras letras usando SUBSTRING (comece em 1, comprimento 3). Para entrada Computer, saia com Com.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.