Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func lchop*(s, sub: string): string =
- ## Remove ``sub`` from the beginning of ``s``.
- runnableExamples:
- let s = "ABcde"
- doAssert s.lchop("AB") == "cde"
- doAssert s.lchop("XXX") == "ABcde"
- if s.startsWith(sub):
- s[sub.len .. s.high]
- else:
- s
- func rchop*(s, sub: string): string =
- ## Remove ``sub`` from the end of ``s``.
- runnableExamples:
- let fname = "stuff.nim"
- doAssert fname.rchop(".nim") == "stuff"
- doAssert fname.rchop(".jpg") == "stuff.nim"
- let longer = "nim is a great language"
- doAssert longer.rchop("uage") == "nim is a great lang"
- if s.endsWith(sub):
- s[0 ..< ^sub.len]
- else:
- s
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement