-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfuncoes_strings.html
More file actions
55 lines (35 loc) · 1.22 KB
/
funcoes_strings.html
File metadata and controls
55 lines (35 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript - JS String</title>
<script>
var nome = 'Daniel Araújo Berriel'
//propriedade length
document.write(nome.length)
document.write('<br />')
//método charAt() -> retorna o caracter da posição passada
document.write(nome.charAt(7))
document.write('<br />')
//método indexOf() -> retorna a primeira posição do caracter passado
//caso não exista o caracter na string, o retorno é -1
document.write(nome.indexOf('e'))
document.write('<br />')
//método replace() -> substitui
//document.write(nome.replace('Araújo Berriel', 'Boy'))
document.write('<br />')
//método substr() -> apartir de uma posição, quantos caracteres se deve recuperar
document.write(nome.substr(7, 4))
document.write('<br />')
//métodos toLowerCase() e toUpperCase()
document.write(nome.toLowerCase())
document.write(nome.toUpperCase())
document.write('<br />')
//método trim() -> remove os espaços nas extremidades da string
var nome1 = ' Daniel Araújo Berriel '
document.write('-' + nome.trim() + '-')
</script>
</head>
<body>
</body>
</html>