📜  在 Julia 中将字符串数组连接成单个字符串– join() 方法

📅  最后修改于: 2022-05-13 01:55:42.442000             🧑  作者: Mango

在 Julia 中将字符串数组连接成单个字符串– join() 方法

join()是 julia 中的一个内置函数,用于将字符串数组连接成单个字符串。指定的分隔符用于在返回的字符串之间插入。

句法:

join([io::IO, ] strings, delim, last) 

参数:

  • [io::IO, ]字符串:指定字符串。
  • delim:指定的分隔符。
  • last:如果给出了 last ,那么最后一个参数被插入到最后两个字符串之间。

返回:它返回一个新的单个字符串。示例 1:

Python
# Julia program to illustrate
# the use of String join() method
 
# Joining an array of strings into a single string.
println(join(["Geeks", "for", "Geeks"]))
println(join(["Geeks", "for", "Geeks"], "-"))
println(join(["Geeks", "for", "Geeks"], "+"))
println(join(["Geeks", "for", "Geeks"], "-", "+"))
println(join(["Geeks", "for", "Geeks", "is", "CSE", "portal"], "-", "+"))


Python
# Julia program to illustrate
# the use of String join() method
 
# Joining an array of strings into a single string.
println(join(["1", "2", "3"]))
println(join(["1", "2", "3"], "-"))
println(join(["1", "2", "3"], "+"))
println(join(["1", "2", "3"], "-", "+"))
println(join(["1", "2", "3", "4", "5", "6"], "-", "+"))


输出:

GeeksforGeeks
Geeks-for-Geeks
Geeks+for+Geeks
Geeks-for+Geeks
Geeks-for-Geeks-is-CSE+portal

示例 2:

Python

# Julia program to illustrate
# the use of String join() method
 
# Joining an array of strings into a single string.
println(join(["1", "2", "3"]))
println(join(["1", "2", "3"], "-"))
println(join(["1", "2", "3"], "+"))
println(join(["1", "2", "3"], "-", "+"))
println(join(["1", "2", "3", "4", "5", "6"], "-", "+"))

输出:

123
1-2-3
1+2+3
1-2+3
1-2-3-4-5+6