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
相關用法
- Julia chomp()用法及代碼示例
- Julia cmp()用法及代碼示例
- Julia string()用法及代碼示例
- Julia Array fill()用法及代碼示例
- Julia Array findall()用法及代碼示例
- Julia Array findprev()用法及代碼示例
- Julia Array findnext()用法及代碼示例
- Julia Array findfirst()用法及代碼示例
- Julia Array findlast()用法及代碼示例
- Julia Array reshape()用法及代碼示例
注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 Join an array of strings into a single string in Julia – join() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。