| English | Português |
|---|---|
| string/strɪŋ/ | string (cadeia de caracteres) |
| ordered sequence/ˈɔːdəd ˈsiːkwəns/ | sequência ordenada |
| characters/ˈkærɪktəz/ | personagens |
| Concatenation/kənˌkætəˈneɪʃn/ | Concatenação |
| Length/leŋθ/ | Duração |
| substring/ˈsʌbstrɪŋ/ | sub-string |
| user input/ˈjuːzə ˈɪnpʊt/ | entrada do usuário |
Text is a string
- Text in a program is stored as a string 字符串.
- A string is an ordered sequence 有序序列 of characters 字符.
- "Hello" is a string of five characters.
- Order matters, so "abc" and "cba" are different strings.
Texto é uma string
- Texto em um programa é armazenado como uma string 字符串.
- Uma string é uma sequência ordenada 有序序列 de caracteres 字符.
- "Hello" é uma string de cinco caracteres.
- A ordem importa, então "abc" e "cba" são strings diferentes.
A string is: · Uma string é:
Order matters, so "abc" ≠ "cba". · A ordem importa, então "abc" ≠ "cba".
Concatenating "sun" and "flower" gives: · Concatenar "sun" e "flower" resulta em:
Concatenation joins them in order into one string. · Concatenação une eles na ordem em uma única string.
What is the length of the string "cat"? · Qual é o comprimento da string "cat"?
It has 3 characters: c, a, t. · Ela tem 3 caracteres: c, a, t.
String operations
- Concatenation 拼接 joins strings into one: "sun" + "flower" gives "sunflower".
- Length 长度 is how many characters a string holds — the length of "cat" is 3.
- A substring 子串 is a part of a string: from "computer" you can take "put".
- You can also read one character by its position.
Operações com string
- Concatenação 拼接 une strings em uma só: "sun" + "flower" resulta em "sunflower".
- Comprimento 长度 é quantos caracteres uma string contém — o comprimento de "cat" é 3.
- Um sub-string 子串 é uma parte de uma string: de "computer" você pode extrair "put".
- Você também pode ler um único caractere pela sua posição.
Index and slice a string · Indexe e fatie uma string
Every character has a position (index from 0). A slice takes characters from the start index up to — but not including — the end index. · Cada caractere tem uma posição (índice a partir de 0). Um fatiamento pega caracteres do índice inicial até — mas não incluindo — o índice final.
If counting starts at 0, the character at position 0 of "cat" is: · Se a contagem começar em 0, o caractere na posição 0 de "cat" é:
Position 0 is the first character, "c". · Posição 0 é o primeiro caractere, "c".
A part of a string, such as "put" from "computer", is called a ______. · Uma parte de uma string, como "put" em "computer", é chamada de ______.
A substring is a slice of the original string. · Uma sub-string é um fatiamento da string original.
Positions and indexing
- Positions are counted from a starting number.
- Many languages start at $0$, so in "cat" position $0$ is "c" and position $2$ is "t".
- A substring takes characters from a start index up to — but not including — an end index.
- Always check where a language starts counting.
Posições e indexação
- As posições são contadas a partir de um número inicial.
- Muitas linguagens começam em $0$, então em "cat" a posição $0$ é "c" e a posição $2$ é "t".
- Um sub-string pega caracteres de um índice inicial até — mas incluindo — um índice final.
- Sempre verifique onde uma linguagem começa a contar.
Concatenating "Hi, " + "Ana" + "!" produces: · Concatenar "Hi, " + "Ana" + "!" produz:
The three strings join in order to greet the user. · As três strings se unem na ordem para saudar o usuário.
Processing user input
- These operations process user input 用户输入 — text a user types, like a name.
- A program might read a name, find its length, and greet the user by joining strings.
Greeting. Read the name "Ana" into name; its length is 3. Build the greeting by concatenation: "Hi, " + name + "!" gives "Hi, Ana!" — the output shown to the user.
Processando entrada do usuário
- Essas operações processam entrada do usuário 用户输入 — texto digitado pelo usuário, como um nome.
- Um programa pode ler um nome, encontrar seu comprimento e saudar o usuário unindo strings.
Saudação. Leia o nome "Ana" em name; seu comprimento é 3. Construa a saudação por concatenação: "Hi, " + name + "!" resulta em "Hi, Ana!" — a saída mostrada ao usuário.
A string is an ordered sequence of characters, so order matters. Key operations are concatenation (join), length (count), and substring (a part). Positions are usually indexed from 0, and a slice runs up to but not including the end index. Strings let a program process user input.
Uma string é uma sequência ordenada de caracteres, então a ordem importa. Operações-chave são concatenação (unir), comprimento (contar) e sub-string (uma parte). As posições geralmente são indexadas a partir de 0, e um recorte vai até mas incluindo o índice final. Strings permitem que um programa processe entrada do usuário.