join

join(strings, delim, [last])

Join an array of strings into a single string, inserting the given delimiter between adjacent strings. If last is given, it will be used instead of delim between the last two strings. For example, join(["apples", "bananas", "pineapples"], ", ", " and ") == "apples, bananas and pineapples".

strings can be any iterable over elements x which are convertible to strings via print(io::IOBuffer, x).

Examples

  1. Join strings with a delimiter:

    julia> fruits = ["apples", "bananas", "oranges"];
    julia> join(fruits, ", ")
    "apples, bananas, oranges"

    This example joins the strings in the fruits array using ", " as the delimiter.

  2. Join strings with a custom last delimiter:

    julia> fruits = ["apples", "bananas", "oranges"];
    julia> join(fruits, ", ", "and")
    "apples, bananas, and oranges"

    It joins the strings in the fruits array using ", " as the delimiter, but the last two strings are separated by "and".

  3. Join strings without any delimiter:
    julia> fruits = ["apple", "banana", "orange"];
    julia> join(fruits, "")
    "applebananaorange"

    In this example, the strings in the fruits array are concatenated without any delimiter.

Common mistake example:

julia> join("apple", "banana", "orange")
ERROR: MethodError: no method matching join(::String, ::String, ::String)

In this example, the join function expects an array of strings as the first argument, but a string was provided instead. Make sure to pass an array of strings to the join function.

See Also

ascii, base64decode, Base64DecodePipe, base64encode, Base64EncodePipe, bin, bits, bytestring, charwidth, chomp, chop, chr2ind, contains, endswith, escape_string, graphemes, ind2chr, iscntrl, istext, isupper, isvalid, join, lcfirst, lowercase, lpad, lstrip, normalize_string, num2hex, parseip, randstring, readuntil, replace, repr, rpad, rsplit, rstrip, search, searchindex, split, startswith, string, stringmime, strip, strwidth, summary, takebuf_string, ucfirst, unescape_string, uppercase, utf16, utf32, utf8, wstring,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: