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 15 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"]
}
43 changes: 41 additions & 2 deletions concepts/strings/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,42 @@ 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"
```
<br />
This conversation was marked as resolved.
Show resolved Hide resolved
Strings can be concatenated via the `+` operator:

```go

fullName := "Jane" + " " + "Austen" // fullName = "Jane Austen"
This conversation was marked as resolved.
Show resolved Hide resolved
```
<br />
This conversation was marked as resolved.
Show resolved Hide resolved
The `strings` package contains many useful functions to work on strings, such as Repeat, ToUpper, ToLower, ReplaceAll, TrimSpace and many more. For getting more information about strings functions check out [strings page](https://pkg.go.dev/strings).
This conversation was marked as resolved.
Show resolved Hide resolved

```go
import "strings"

// Returns all the received character(s) to their lower case by (strings.ToLower(s string)
This conversation was marked as resolved.
Show resolved Hide resolved
fmt.Println(strings.ToLower("MaKEmeLoweRCase")) // Output: "makemelowercase"
This conversation was marked as resolved.
Show resolved Hide resolved

// Returns all the received character(s) to their upper case by (strings.ToUpper(s string))
This conversation was marked as resolved.
Show resolved Hide resolved
fmt.Println(strings.ToUpper("MaKemeUpPercaSe")) // Output: "MAKEMEUPPERCASE"
This conversation was marked as resolved.
Show resolved Hide resolved

Some values need to be escaped:
// Returns a new string consisting of count copies of the string s by (strings.Repeat(s string, n int))
This conversation was marked as resolved.
Show resolved Hide resolved
fmt.Println(strings.Repeat("Go", 3)) // Output: "GoGoGo"
This conversation was marked as resolved.
Show resolved Hide resolved

// Returns a copy of the string s with all non-overlapping instances of old replaced by new by (strings.ReplaceAll(s, old, new string))
This conversation was marked as resolved.
Show resolved Hide resolved
fmt.Println(strings.ReplaceAll("your cat is playing with your pillow", "your", "my")) // Output: "my cat is playing with my pillow
This conversation was marked as resolved.
Show resolved Hide resolved

// Returns a slice of the string s, with all leading and trailing white space removed by (strings.TrimSpace(s string))
This conversation was marked as resolved.
Show resolved Hide resolved
fmt.Println(strings.TrimSpace(" \t\n Hello, Gophers \n\t\r\n")) // Output: "Hello, Gophers"
This conversation was marked as resolved.
Show resolved Hide resolved

```
<br />
This conversation was marked as resolved.
Show resolved Hide resolved

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

| Value | Description |
| ----- | -------------------- |
Expand All @@ -24,7 +55,13 @@ 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
This conversation was marked as resolved.
Show resolved Hide resolved
```

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Apart from the example given here, I think it would be useful to include another one where special characters like \nare used to show the difference. We do something similar in the regular expressions concept where a regular double-quoted string literal is compared to a raw string literal:

"\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'

You can think of a better example, but feel free to use the same example as the one in that concept if you want. Since this is relevant in both places, I don't mind a little bit of repetition.

Expand All @@ -35,3 +72,5 @@ William
Jack
Averell`
```


34 changes: 30 additions & 4 deletions concepts/strings/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,43 @@ A `string` in Go is an immutable sequence of bytes, which don't necessarily have
A `string` literal is a sequence of bytes enclosed in double quotes:

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

Strings can be concatenated via the `+` operator:

```go
fullName := "Jane" + " " + "Austen"
fullName := "Jane" + " " + "Austen" // fullName = "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 `\b` for Backspace and `\n` for new lines in strings.
This conversation was marked as resolved.
Show resolved Hide resolved
```go
Dialogue := "How is the weather today?\nIt's sunny"


// Dialogue = "How is the weather today?
// It's sunny"
This conversation was marked as resolved.
Show resolved Hide resolved
```


The `strings` package contains many useful functions to work on strings, such as Repeat, ToUpper, ToLower, ReplaceAll, TrimSpace and many more. For getting more information about strings functions check out [strings page](https://pkg.go.dev/strings).

```go
question := "\t or spaces?"
import "strings"

// Returns all the received character(s) to their lower case by (strings.ToLower(s string)
fmt.Println(strings.ToLower("MaKEmeLoweRCase")) // Output: "makemelowercase"

// Returns all the received character(s) to their upper case by (strings.ToUpper(s string))
fmt.Println(strings.ToUpper("MaKemeUpPercaSe")) // Output: "MAKEMEUPPERCASE"

// Returns a new string consisting of count copies of the string s by (strings.Repeat(s string, n int))
fmt.Println(strings.Repeat("Go", 3)) // Output: "GoGoGo"

// Returns a copy of the string s with all non-overlapping instances of old replaced by new by (strings.ReplaceAll(s, old, new string))
fmt.Println(strings.ReplaceAll("your cat is playing with your pillow", "your", "my")) // Output: "my cat is playing with my pillow

// Returns a slice of the string s, with all leading and trailing white space removed by (strings.TrimSpace(s string))
fmt.Println(strings.TrimSpace(" \t\n Hello, Gophers \n\t\r\n")) // Output: "Hello, Gophers"

```
30 changes: 24 additions & 6 deletions exercises/concept/welcome-to-tech-palace/.docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,37 @@ firstName := "Jane"
Strings can be concatenated via the `+` operator:

```go
fullName := "Jane" + " " + "Austen"
fullName := "Jane" + " " + "Austen" // fullName = "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 `\b` for Backspace and `\n` for new lines in strings.
```go
question := "\t or spaces?"
Dialogue := "How is the weather today?\nIt's sunny"


// Dialogue = "How is the weather today?
// It's sunny"
```

The `strings` package contains many useful functions to work on strings.

The `strings` package contains many useful functions to work on strings, such as Repeat, ToUpper, ToLower, ReplaceAll, TrimSpace and many more. For getting more information about strings functions check out [strings page](https://pkg.go.dev/strings).

```go
import "strings"

strings.ToLower("TEST") // Output: "test"
// Returns all the received character(s) to their lower case by (strings.ToLower(s string)
fmt.Println(strings.ToLower("MaKEmeLoweRCase")) // Output: "makemelowercase"

// Returns all the received character(s) to their upper case by (strings.ToUpper(s string))
fmt.Println(strings.ToUpper("MaKemeUpPercaSe")) // Output: "MAKEMEUPPERCASE"

// Returns a new string consisting of count copies of the string s by (strings.Repeat(s string, n int))
fmt.Println(strings.Repeat("Go", 3)) // Output: "GoGoGo"

// Returns a copy of the string s with all non-overlapping instances of old replaced by new by (strings.ReplaceAll(s, old, new string))
fmt.Println(strings.ReplaceAll("your cat is playing with your pillow", "your", "my")) // Output: "my cat is playing with my pillow

// Returns a slice of the string s, with all leading and trailing white space removed by (strings.TrimSpace(s string))
fmt.Println(strings.TrimSpace(" \t\n Hello, Gophers \n\t\r\n")) // Output: "Hello, Gophers"

```
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