Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add more details and examples to the introduction #2171

Merged
merged 39 commits into from Apr 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
bc4a9f8
add more details and examples to the introduction
Apr 10, 2022
5343040
add my Github username in contributors
Apr 10, 2022
f641749
Add my Github username in contributors
Apr 10, 2022
544e0ef
Remove "Output" in comments
Apr 10, 2022
92781c2
Sync the changes with the related code
Apr 10, 2022
7eb0186
Remove output from non-Println code blocks
Apr 10, 2022
b2c4011
add more details for the examples
Apr 10, 2022
a90cc48
Sync with the other introduction
Apr 10, 2022
59689e8
Sync with the introduction
Apr 10, 2022
22f98c8
Update about.md
Apr 10, 2022
6ef5346
Update about.md
Apr 10, 2022
26b1876
Update introduction.md
Apr 10, 2022
7341e1c
Update introduction.md
Apr 10, 2022
aa1ce06
Update introduction.md
Apr 10, 2022
ad0ba20
Update introduction.md
Apr 10, 2022
8c47c7b
Update concepts/strings/about.md
Apr 12, 2022
9c9b939
Update concepts/strings/about.md
Apr 12, 2022
692f7db
Update concepts/strings/about.md
Apr 12, 2022
f3a2276
Update concepts/strings/about.md
Apr 12, 2022
4906b1d
Update concepts/strings/about.md
Apr 12, 2022
357ec91
Update concepts/strings/introduction.md
Apr 12, 2022
7bf2d1c
Update concepts/strings/about.md
Apr 12, 2022
8941cb7
Update concepts/strings/about.md
Apr 12, 2022
b104073
Update concepts/strings/about.md
Apr 12, 2022
8161573
Update concepts/strings/introduction.md
Apr 12, 2022
973243a
Update concepts/strings/about.md
Apr 12, 2022
496df9f
Update concepts/strings/about.md
Apr 13, 2022
ccbce35
Update concepts/strings/about.md
Apr 13, 2022
61c907a
Update concepts/strings/about.md
Apr 13, 2022
f5c0b64
Update concepts/strings/about.md
Apr 13, 2022
26e96c1
Update concepts/strings/about.md
Apr 13, 2022
1447c24
Update concepts/strings/about.md
Apr 13, 2022
e0791ab
Update concepts/strings/about.md
Apr 13, 2022
f00bffc
Update about.md
Apr 13, 2022
361567e
Update introduction.md
Apr 13, 2022
a9c257d
Update introduction.md
Apr 13, 2022
4a052a1
Update introduction.md
Apr 13, 2022
5cb9108
Update introduction.md
Apr 13, 2022
d0ce47a
Update formatting examples
andrerfcsantos Apr 15, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion concepts/strings/.meta/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"blurb": "A string in Go is an immutable sequence of bytes, which don't necessarily have to represent characters.",
"authors": ["tehsphinx", "erikschierboom"],
"contributors": []
"contributors": ["kekimaker"]
}
62 changes: 59 additions & 3 deletions concepts/strings/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,36 @@ A `string` in Go is an immutable sequence of bytes, which don't necessarily have

A string literal is defined between double quotes:


```go
const name = "Jane"
```

Some values need to be escaped:
Strings can be concatenated via the `+` operator:

```go

fullName := "Jane" + " " + "Austen"
// "Jane Austen"
```

The `strings` package contains many useful functions to work on strings.
For more information about string functions, check out the [strings package documentation](https://pkg.go.dev/strings).
Here are some examples:

```go
import "strings"

// strings.ToLower returns the string given as argument with all its characters lowercased
strings.ToLower("MaKEmeLoweRCase")
// "makemelowercase"

// strings.Repeat returns a string with a substring given as argument repeated many times
strings.Repeat("Go", 3)
// "GoGoGo"
```

Some special characters need to be escaped with a leading backslash:

| Value | Description |
| ----- | -------------------- |
Expand All @@ -24,14 +49,45 @@ Some values need to be escaped:
| `\"` | Double quote |

```go
const daltons = "Joe\nWilliam\nJack\nAverell"
fmt.Println("Joe\nWilliam\nJack\nAverell")

// Output:
// Joe
// William
// Jack
// Averell
```

Raw string literals use backticks (\`) as their delimiter instead of double quotes and are interpreted literally, meaning that there is no need to escape characters or newlines.
## Raw string literals

Raw string literals use backticks (\`) as their delimiter instead of double quotes and all characters in it are interpreted literally, meaning that there is no need to escape characters or newlines.

This is an example of a multiline string:

```go
const daltons = `Joe
William
Jack
Averell`
```

This string has multiple lines. More specifically, it has 3 `\n`. However, because we are a raw string literal, we don't need to put the `\n` explicitly in the string. The newlines will be interpreted literally.

Here are some other examples comparing raw string literals with regular string literals:

```go
`abc`
// same as "abc"

"\"" // regular string literal with 1 character: a double quote
// same as `"` a raw string literal with 1 character: a double quote

`\n
` // raw string literal with 3 character: a backslash, an 'n', and a newline
// same as "\\n\n" a regular string literal with 3 characters: a backslash, an 'n', and a newline

"\t\n" // regular string literal with 2 characters: a tab and a newline
`\t\n`// raw string literal with 4 characters: two backslashes, a 't', and an 'n'
```


30 changes: 25 additions & 5 deletions concepts/strings/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,40 @@

A `string` in Go is an immutable sequence of bytes, which don't necessarily have to represent characters.

A `string` literal is a sequence of bytes enclosed in double quotes:
A string literal is defined between double quotes:


```go
name := "Jane"
const name = "Jane"
```

Strings can be concatenated via the `+` operator:

```go

fullName := "Jane" + " " + "Austen"
// "Jane Austen"
```

Some special characters need to be escaped with a leading backslash:
Some special characters need to be escaped with a leading backslash, such as `\t` for a tab and `\n` for a new line in strings.

```go
question := "\t or spaces?"
Dialogue := "How is the weather today?\nIt's sunny"
// "How is the weather today?
// It's sunny"
```

The `strings` package contains many useful functions to work on strings.
For more information about string functions, check out the [strings package documentation](https://pkg.go.dev/strings).
Here are some examples:

```go
import "strings"

// strings.ToLower returns the string given as argument with all its characters lowercased
strings.ToLower("MaKEmeLoweRCase")
// "makemelowercase"

// strings.Repeat returns a string with a substring given as argument repeated many times
strings.Repeat("Go", 3)
// "GoGoGo"
```
21 changes: 16 additions & 5 deletions exercises/concept/welcome-to-tech-palace/.docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,39 @@

A `string` in Go is an immutable sequence of bytes, which don't necessarily have to represent characters.

A `string` literal is a sequence of bytes enclosed in double quotes:
A string literal is defined between double quotes:

```go
firstName := "Jane"
const name = "Jane"
```

Strings can be concatenated via the `+` operator:

```go
fullName := "Jane" + " " + "Austen"
// "Jane Austen"
```

Some special characters need to be escaped with a leading backslash:
Some special characters need to be escaped with a leading backslash, such as `\t` for a tab and `\n` for a new line in strings.

```go
question := "\t or spaces?"
Dialogue := "How is the weather today?\nIt's sunny"
// "How is the weather today?
// It's sunny"
```

The `strings` package contains many useful functions to work on strings.
For more information about string functions, check out the [strings package documentation](https://pkg.go.dev/strings).
Here are some examples:

```go
import "strings"

strings.ToLower("TEST") // Output: "test"
// strings.ToLower returns the string given as argument with all its characters lowercased
strings.ToLower("MaKEmeLoweRCase")
// "makemelowercase"

// strings.Repeat returns a string with a substring given as argument repeated many times
strings.Repeat("Go", 3)
// "GoGoGo"
```
1 change: 1 addition & 0 deletions exercises/concept/welcome-to-tech-palace/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"junedev"
],
"contributors": [
"kekimaker"
],
"files": {
"solution": [
Expand Down