当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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"], "-", "+"))

输出:

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




相关用法


注:本文由纯净天空筛选整理自Kanchan_Ray大神的英文原创作品 Join an array of strings into a single string in Julia – join() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。