summaryrefslogtreecommitdiff
path: root/strings/strings.go
diff options
context:
space:
mode:
Diffstat (limited to 'strings/strings.go')
-rw-r--r--strings/strings.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/strings/strings.go b/strings/strings.go
index 269e760f..073375e7 100644
--- a/strings/strings.go
+++ b/strings/strings.go
@@ -2,6 +2,7 @@
package strings
import (
+ "fmt"
"regexp"
"sort"
"strings"
@@ -125,3 +126,22 @@ func WordWrap(in string, opts WordWrapOpts) string {
opts = wwDefaults(opts)
return goutils.WrapCustom(in, int(opts.Width), opts.LBSeq, false)
}
+
+// SkipLines - skip the given number of lines (ending with \n) from the string.
+// If skip is greater than the number of lines in the string, an empty string is
+// returned.
+func SkipLines(skip int, in string) (string, error) {
+ if skip < 0 {
+ return "", fmt.Errorf("skip must be >= 0")
+ }
+ if skip == 0 {
+ return in, nil
+ }
+
+ lines := strings.SplitN(in, "\n", skip+1)
+ if skip >= len(lines) {
+ return "", nil
+ }
+
+ return lines[skip], nil
+}