Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
11 changes: 8 additions & 3 deletions concepts/strings-package/.meta/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"blurb": "The standard library strings package includes great utility functions to work with strings.",
"authors": ["tehsphinx", "erikschierboom"],
"contributors": []
"blurb": "The standard library \"strings\" package includes utility functions to work with strings.",
"authors": [
"tehsphinx",
"erikschierboom"
],
"contributors": [
"BNAndras"
]
}
51 changes: 36 additions & 15 deletions concepts/strings-package/about.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,44 @@
# About

The [`strings` package](https://pkg.go.dev/strings) contains many useful functions to work on strings:
The [`strings` package](https://pkg.go.dev/strings) provides functions for working with strings.
Below are some of the functions in the package; check out the documentation to see the rest!

| Function | Purpose |
| --------------------------------------------------- | ------------------------------------------------------------------- |
| [ToLower](https://pkg.go.dev/strings#ToLower) | Convert the string to lower case |
| [ToUpper](https://pkg.go.dev/strings#ToUpper) | Convert the string to upper case |
| [TrimSpace](https://pkg.go.dev/strings#TrimSpace) | Trim leading and trailing whitespace |
| [Index](https://pkg.go.dev/strings#Index) | Find the index of the first instance of a substring within a string |
| [Replace](https://pkg.go.dev/strings#Replace) | Replace one occurrence of a substring in a string |
| [ReplaceAll](https://pkg.go.dev/strings#ReplaceAll) | Replace all occurrences of a substring in a string |
| [Split](https://pkg.go.dev/strings#Split) | Split a string into parts based on a separator |
| [HasSuffix](https://pkg.go.dev/strings#HasSuffix) | Check if a string ends with a specific substring |
| [Count](https://pkg.go.dev/strings#Count) | Count the number of occurrences of a substring within a string |
| Role | Function | Purpose |
| --------------------- | --------------------------------------------------- | ------------------------------------------------------------------- |
| Case Conversion | [ToLower](https://pkg.go.dev/strings#ToLower) | Convert a string to lower case |
| Case Conversion | [ToUpper](https://pkg.go.dev/strings#ToUpper) | Convert a string to upper case |
| Searching | [Contains](https://pkg.go.dev/strings#Contains) | Check if a string contains a specific substring |
| Searching | [Count](https://pkg.go.dev/strings#Count) | Count non-overlapping occurrences of a substring |
| Searching | [HasPrefix](https://pkg.go.dev/strings#HasPrefix) | Check if a string starts with a specific substring |
| Searching | [HasSuffix](https://pkg.go.dev/strings#HasSuffix) | Check if a string ends with a specific substring |
Comment thread
BNAndras marked this conversation as resolved.
| Searching | [Index](https://pkg.go.dev/strings#Index) | Return the index of the first occurrence of a substring, or -1 |
| Modifying | [Replace](https://pkg.go.dev/strings#Replace) | Replace up to n occurrences of a substring |
| Modifying | [ReplaceAll](https://pkg.go.dev/strings#ReplaceAll) | Replace all occurrences of a substring |
| Modifying | [TrimSpace](https://pkg.go.dev/strings#TrimSpace) | Remove leading and trailing whitespace |
| Splitting or Joining | [Join](https://pkg.go.dev/strings#Join) | Join a slice of strings with a separator |
| Splitting or Joining | [Split](https://pkg.go.dev/strings#Split) | Split a string into parts on a separator |
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

FieldsSeq and SplitSeq might be work mentioning.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That's fine by me, but the additional code examples might need some explanation given that range iteration is covered way later in the syllabus. Slices are also later in the syllabus but they're not as far so they're probably okay.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

sigh Building a syllabus where you can only mention prior topics is hard.

I think a comment mentioning "Don't worry about this syntax too much; we discuss it in the range concept later" should suffice.


```go
import "strings"

strings.ToLower("Gopher") // => "gopher"
strings.Index("Apple", "le") // => 3
strings.Count("test", "t") // => 2
// Case conversion
strings.ToLower("Gopher") // "gopher"
strings.ToUpper("Gopher") // "GOPHER"

// Searching
strings.Contains("Apple", "le") // true
strings.Index("Apple", "le") // 3
strings.Index("Apple", "xyz") // -1
strings.Count("test", "t") // 2
strings.HasPrefix("Gopher", "Go") // true
strings.HasSuffix("Gopher", "er") // true

// Modifying
strings.TrimSpace(" hello ") // "hello"
strings.Replace("aabbcc", "b", "x", 1) // "aaxbcc"
strings.ReplaceAll("aabbcc", "b", "x") // "aaxxcc"

// Splitting or Joining
strings.Split("a,b,c", ",") // []string{"a", "b", "c"}
strings.Join([]string{"a", "b", "c"}, ",") // "a,b,c"
```
36 changes: 34 additions & 2 deletions concepts/strings-package/introduction.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,41 @@
# Introduction
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should the files be synced?


The `strings` package contains many useful functions to work on strings.
The [`strings` package](https://pkg.go.dev/strings) provides functions for working with strings:

| Role | Function | Purpose |
| --------------------- | --------------------------------------------------- | ------------------------------------------------------------------- |
| Case Conversion | [ToLower](https://pkg.go.dev/strings#ToLower) | Convert a string to lower case |
| Case Conversion | [ToUpper](https://pkg.go.dev/strings#ToUpper) | Convert a string to upper case |
| Searching | [Contains](https://pkg.go.dev/strings#Contains) | Check if a string contains a specific substring |
| Searching | [Count](https://pkg.go.dev/strings#Count) | Count non-overlapping occurrences of a substring |
| Searching | [HasSuffix](https://pkg.go.dev/strings#HasSuffix) | Check if a string ends with a specific substring |
| Searching | [Index](https://pkg.go.dev/strings#Index) | Return the index of the first occurrence of a substring, or -1 |
| Modifying | [Replace](https://pkg.go.dev/strings#Replace) | Replace up to n occurrences of a substring |
| Modifying | [ReplaceAll](https://pkg.go.dev/strings#ReplaceAll) | Replace all occurrences of a substring |
| Modifying | [TrimSpace](https://pkg.go.dev/strings#TrimSpace) | Remove leading and trailing whitespace |
| Splitting or Joining | [Join](https://pkg.go.dev/strings#Join) | Join a slice of strings with a separator |
| Splitting or Joining | [Split](https://pkg.go.dev/strings#Split) | Split a string into parts on a separator |

```go
import "strings"

strings.ToUpper("test") // => "TEST"
// Case conversion
strings.ToLower("Gopher") // "gopher"
strings.ToUpper("Gopher") // "GOPHER"

// Searching
strings.Contains("Apple", "le") // true
strings.Index("Apple", "le") // 3
strings.Index("Apple", "xyz") // -1
strings.Count("test", "t") // 2
strings.HasSuffix("Gopher", "er") // true

// Modifying
strings.TrimSpace(" hello ") // "hello"
strings.Replace("aabbcc", "b", "x", 1) // "aaxbcc"
strings.ReplaceAll("aabbcc", "b", "x") // "aaxxcc"

// Splitting or Joining
strings.Split("a,b,c", ",") // []string{"a", "b", "c"}
strings.Join([]string{"a", "b", "c"}, ",") // "a,b,c"
```
Loading