diff --git a/base/strings/basic.jl b/base/strings/basic.jl index 3c1c5cc0ce498..c3c0e181fbb03 100644 --- a/base/strings/basic.jl +++ b/base/strings/basic.jl @@ -59,20 +59,21 @@ sizeof(s::AbstractString) = error("type $(typeof(s)) has no canonical binary rep eltype(::Type{<:AbstractString}) = Char """ -``` -*(s::AbstractString, t::AbstractString) -``` + *(s::Union{AbstractString, Char}, t::Union{AbstractString, Char}...) -Concatenate strings. The `*` operator is an alias to this function. - -# Example +Concatenate strings and/or characters, producing a [`String`](@ref). This is equivalent +to calling the [`string`](@ref) function on the arguments. +# Examples ```jldoctest julia> "Hello " * "world" "Hello world" + +julia> 'j' * "ulia" +"julia" ``` """ -(*)(s1::AbstractString, ss::AbstractString...) = string(s1, ss...) +(*)(s1::Union{Char, AbstractString}, ss::Union{Char, AbstractString}...) = string(s1, ss...) one(::Union{T,Type{T}}) where {T<:AbstractString} = convert(T, "") diff --git a/test/strings/basic.jl b/test/strings/basic.jl index 49ec6c369a84e..21c8a086850bd 100644 --- a/test/strings/basic.jl +++ b/test/strings/basic.jl @@ -484,3 +484,10 @@ Base.endof(x::CharStr) = endof(x.chars) # issue #12495: check that logical indexing attempt raises ArgumentError @test_throws ArgumentError "abc"[[true, false, true]] @test_throws ArgumentError "abc"[BitArray([true, false, true])] + +@test "ab" * "cd" == "abcd" +@test 'a' * "bc" == "abc" +@test "ab" * 'c' == "abc" +@test 'a' * 'b' == "ab" +@test 'a' * "b" * 'c' == "abc" +@test "a" * 'b' * 'c' == "abc"