Recent Changes - Search:

Oktatás

* Programozás 1
  + feladatsor
  + GitHub oldal

* Szkriptnyelvek
  + feladatsor
  + quick link

Teaching

Programming 1 (BI)
  ▸ exercises
  ▸ quick link

teaching assets


Félévek

* 2025/26/2
* archívum


Linkek

* kalendárium
* tételsorok
* jegyzetek
* szakdolgozat / PhD
* ösztöndíjak
* certificates
* C lang.
* C#
* D lang.
* Java
* Nim
* Nim2
  + exercises
* XC=BASIC
* old
  ✦C++, ✦Clojure, ✦Scala


[ edit | logout ]
[ sandbox | passwd ]

removePrefix, removeSuffix

See also std/strutils

Python also has these two string methods. However, in Python, they return a new string object. In Nim, they modify the string in-place. If you want a Python-like behaviour, you can do that with a custom function.

removePrefix()

removePrefix()
s = "https://python.org"

print(s.removeprefix("https://"))  # python.org

print(s.removeprefix("ftp://"))  # https://python.org
import std/strutils

var s = "https://python.org"  # var, can be modified

s.removePrefix("https://")  # change in-place

echo s  # python.org ; `s` has changed!

# ---

func withoutPrefix*(s, prefix: string): string =
  ## Remove the given prefix. Returns a new string.
  result = s
  result.removePrefix(prefix)

let url  = "https://python.org"  # let, immutable

echo url.withoutPrefix("https://")  # python.org

echo url  # https://python.org ; original string

removeSuffix()

Can be done similarly to removePrefix() .

Cloud City

  

Blogjaim, hobbi projektjeim

* The Ubuntu Incident
* Python Adventures
* @GitHub
* heroku
* extra
* haladó Python
* YouTube listák


Debrecen | la France


[ edit ]

Edit - History - Print *** Report - Recent Changes - Search
Page last modified on 2026 May 17, 14:45