mirror of
https://github.com/jbranchaud/til
synced 2026-01-17 22:18:01 +00:00
Compare commits
4 Commits
69c6d99c74
...
43dd12d7a8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
43dd12d7a8 | ||
|
|
b376f32a67 | ||
|
|
5615da920f | ||
|
|
c60c63f554 |
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
|
||||
|
||||
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
||||
|
||||
_1523 TILs and counting..._
|
||||
_1524 TILs and counting..._
|
||||
|
||||
---
|
||||
|
||||
@@ -191,7 +191,7 @@ _1523 TILs and counting..._
|
||||
- [Aliasing An Ansible Host](devops/aliasing-an-ansible-host.md)
|
||||
- [Allow Cross-Origin Requests To Include Cookies](devops/allow-cross-origin-requests-to-include-cookies.md)
|
||||
- [Allow HTTPS Through Your UFW Firewall](devops/allow-https-through-your-ufw-firewall.md)
|
||||
- [Check For Cached Site Assocation File For iOS](devops/check-for-cached-site-association-file-for-ios.md)
|
||||
- [Check For Cached Site Association File For iOS](devops/check-for-cached-site-association-file-for-ios.md)
|
||||
- [Check The Status of All Services](devops/check-the-status-of-all-services.md)
|
||||
- [Check The Syntax Of nginx Files](devops/check-the-syntax-of-nginx-files.md)
|
||||
- [Connect To An RDS PostgreSQL Database](devops/connect-to-an-rds-postgresql-database.md)
|
||||
@@ -402,6 +402,7 @@ _1523 TILs and counting..._
|
||||
- [Do Something N Times](go/do-something-n-times.md)
|
||||
- [Find Executables Installed By Go](go/find-executables-installed-by-go.md)
|
||||
- [Not So Random](go/not-so-random.md)
|
||||
- [Parse A String Into Individual Fields](go/parse-a-string-into-individual-fields.md)
|
||||
- [Replace The Current Process With An External Command](go/replace-the-current-process-with-an-external-command.md)
|
||||
- [Sleep For A Duration](go/sleep-for-a-duration.md)
|
||||
- [Upgrading From An Older Version On Mac](go/upgrading-from-an-older-version-on-mac.md)
|
||||
@@ -732,7 +733,7 @@ _1523 TILs and counting..._
|
||||
- [Check If Clusters Are Upgrade Compatible](postgres/check-if-clusters-are-upgrade-compatible.md)
|
||||
- [Check If The Local Server Is Running](postgres/check-if-the-local-server-is-running.md)
|
||||
- [Check If User Role Exists For Database](postgres/check-if-user-role-exists-for-database.md)
|
||||
- [Check Table For Any Oprhaned Records](postgres/check-table-for-any-orphaned-records.md)
|
||||
- [Check Table For Any Orphaned Records](postgres/check-table-for-any-orphaned-records.md)
|
||||
- [Checking Inequality](postgres/checking-inequality.md)
|
||||
- [Checking The Type Of A Value](postgres/checking-the-type-of-a-value.md)
|
||||
- [Clear The Screen In psql](postgres/clear-the-screen-in-psql.md)
|
||||
|
||||
39
go/parse-a-string-into-individual-fields.md
Normal file
39
go/parse-a-string-into-individual-fields.md
Normal file
@@ -0,0 +1,39 @@
|
||||
# Parse A String Into Individual Fields
|
||||
|
||||
Let's say you're reading in data from a file or otherwise dealing with an
|
||||
arbitrary string of data. If that string has a series of values separated by
|
||||
whitespace, you can parse it into individual fields with
|
||||
[`strings.Fields`](https://pkg.go.dev/strings#Fields).
|
||||
|
||||
```go
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
data := "3 5 2 6 7 1 9"
|
||||
fields := strings.Fields(data)
|
||||
|
||||
fmt.Printf("Fields: %v", fields)
|
||||
// [3 5 2 6 7 1 9]
|
||||
}
|
||||
```
|
||||
|
||||
Here is another example where we can see that `strings.Fields` deals with
|
||||
multiple whitespace and surrounding whitespace:
|
||||
|
||||
```go
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
data := " go java c++ rust "
|
||||
fields := strings.Fields(data)
|
||||
|
||||
fmt.Printf("%v", fields)
|
||||
// [go java c++ rust]
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user