Documentation
¶
Overview ¶
Package strscan provides functions to scan and iterate over strings.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Reversed ¶
Reversed scans the string s for instances of sep, returning the substrings via an iterator. Reversed starts at len(s) and stops at 0.
If trim is true, substrings will have any leading and trailing space characters removed before being passed to the iterator.
If a substring is empty, it will be silently skipped. A substring is considered empty when it's length is 0. This is caused by s containing back-to-back separators or when the substring consists entirely of space characters (only when trim is enabled).
Example ¶
package main import ( "fmt" "github.com/matthewpi/strscan" ) func main() { for s := range strscan.Reversed("1.1.1.1, 127.0.0.1, ::1", ',', false) { // quotes were added to show that trim removes whitespace fmt.Printf("\"%s\"\n", s) } fmt.Println() for s := range strscan.Reversed("1.1.1.1, 127.0.0.1, ::1", ',', true) { // quotes were added to show that trim removes whitespace fmt.Printf("\"%s\"\n", s) } }
Output: " ::1" " 127.0.0.1" "1.1.1.1" "::1" "127.0.0.1" "1.1.1.1"
func Scan ¶
Scan scans the string s for instances of sep, returning the substrings via an iterator. Scan starts from index 0 and stops at len(s).
If trim is true, substrings will have any leading and trailing space characters removed before being passed to the iterator.
If a substring is empty, it will be silently skipped. A substring is considered empty when it's length is 0. This is caused by s containing back-to-back separators or when the substring consists entirely of space characters (only when trim is enabled).
Example ¶
package main import ( "fmt" "github.com/matthewpi/strscan" ) func main() { for s := range strscan.Scan("1.1.1.1, 127.0.0.1, ::1", ',', false) { // quotes were added to show that trim removes whitespace fmt.Printf("\"%s\"\n", s) } fmt.Println() for s := range strscan.Scan("1.1.1.1, 127.0.0.1, ::1", ',', true) { // quotes were added to show that trim removes whitespace fmt.Printf("\"%s\"\n", s) } }
Output: "1.1.1.1" " 127.0.0.1" " ::1" "1.1.1.1" "127.0.0.1" "::1"
Types ¶
This section is empty.