232232# chop(s::AbstractString) = SubString(s, firstindex(s), prevind(s, lastindex(s)))
233233
234234"""
235- chopprefix(s::AbstractString, prefix::Union{AbstractString,Regex})::SubString
235+ chopprefix(s::AbstractString, prefix::Union{AbstractString,Regex,AbstractChar })::SubString
236236
237237Remove the prefix `prefix` from `s`. If `s` does not start with `prefix`, a string equal to `s` is returned.
238238
@@ -241,6 +241,9 @@ See also [`chopsuffix`](@ref).
241241!!! compat "Julia 1.8"
242242 This function is available as of Julia 1.8.
243243
244+ !!! compat "Julia 1.13"
245+ The method which accepts an `AbstractChar` prefix is available as of Julia 1.13.
246+
244247# Examples
245248```jldoctest
246249julia> chopprefix("Hamburger", "Ham")
@@ -272,8 +275,16 @@ function chopprefix(s::Union{String, SubString{String}},
272275 end
273276end
274277
278+ function chopprefix (s:: AbstractString , prefix:: AbstractChar )
279+ if ! isempty (s) && first (s) == prefix
280+ return SubString (s, nextind (s, firstindex (s)))
281+ else
282+ return SubString (s)
283+ end
284+ end
285+
275286"""
276- chopsuffix(s::AbstractString, suffix::Union{AbstractString,Regex})::SubString
287+ chopsuffix(s::AbstractString, suffix::Union{AbstractString,Regex,AbstractChar })::SubString
277288
278289Remove the suffix `suffix` from `s`. If `s` does not end with `suffix`, a string equal to `s` is returned.
279290
@@ -282,6 +293,9 @@ See also [`chopprefix`](@ref).
282293!!! compat "Julia 1.8"
283294 This function is available as of Julia 1.8.
284295
296+ !!! compat "Julia 1.13"
297+ The method which accepts an `AbstractChar` suffix is available as of Julia 1.13.
298+
285299# Examples
286300```jldoctest
287301julia> chopsuffix("Hamburger", "er")
@@ -315,6 +329,13 @@ function chopsuffix(s::Union{String, SubString{String}},
315329 end
316330end
317331
332+ function chopsuffix (s:: AbstractString , suffix:: AbstractChar )
333+ if ! isempty (s) && last (s) == suffix
334+ return SubString (s, firstindex (s), prevind (s, lastindex (s)))
335+ else
336+ return SubString (s)
337+ end
338+ end
318339
319340"""
320341 chomp(s::AbstractString)::SubString
0 commit comments