mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-12 22:33:49 +00:00
Adds split proc for strings with a string separator.
This commit is contained in:
@@ -264,6 +264,19 @@ iterator split*(s: string, sep: char): string =
|
||||
yield substr(s, first, last-1)
|
||||
inc(last)
|
||||
|
||||
iterator split*(s: string, sep: string): string =
|
||||
## Splits the string `s` into substrings using a string separator.
|
||||
##
|
||||
## Substrings are separated by the string `sep`.
|
||||
var last = 0
|
||||
if len(s) > 0:
|
||||
while last <= len(s):
|
||||
var first = last
|
||||
while last < len(s) and s.substr(last, last + <sep.len) != sep:
|
||||
inc(last)
|
||||
yield substr(s, first, last-1)
|
||||
inc(last, sep.len)
|
||||
|
||||
iterator splitLines*(s: string): string =
|
||||
## Splits the string `s` into its containing lines. Every newline
|
||||
## combination (CR, LF, CR-LF) is supported. The result strings contain
|
||||
@@ -329,6 +342,13 @@ proc split*(s: string, sep: char): seq[string] {.noSideEffect,
|
||||
## of substrings.
|
||||
accumulateResult(split(s, sep))
|
||||
|
||||
proc split*(s: string, sep: string): seq[string] {.noSideEffect,
|
||||
rtl, extern: "nsuSplitString".} =
|
||||
## Splits the string `s` into substrings using a string separator.
|
||||
##
|
||||
## Substrings are separated by the string `sep`.
|
||||
accumulateResult(split(s, sep))
|
||||
|
||||
proc toHex*(x: BiggestInt, len: int): string {.noSideEffect,
|
||||
rtl, extern: "nsuToHex".} =
|
||||
## Converts `x` to its hexadecimal representation. The resulting string
|
||||
|
||||
Reference in New Issue
Block a user