There is a removeFirst(_:)
method on String. However, the documentation seems very generic and doesn't mention anything about being specific to a string:
k: The number of elements to remove from the collection. k must be greater than or equal to zero and must not exceed the number of elements in the collection.
var bugs = ["Aphid", "Bumblebee", "Cicada", "Damselfly", "Earwig"] bugs.removeFirst(3) print(bugs) // Prints "["Damselfly", "Earwig"]"
In fact, it looks very similar to the Array or Collection documentation of removeFirst(_:).
Since there are at least 6 different ways to get the character count in Swift, it makes it difficult to know which count I should use for k
.
If I want to create a method such as string.removePrefix("foo")
, which of the 6 character counts should I use?