當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Julia repeat()用法及代碼示例


這個repeat()是 julia 中的一個內置函數,用於返回一個字符串,該字符串是指定字符串重複指定次數的字符串。

用法:
repeat(String::AbstractString, r::Integer)

參數:

  • String:指定的字符串或字符
  • r::整數:指定次數

返回值:它返回一個字符串,它是指定字符串重複指定次數的字符串。

範例1:




# Julia program to illustrate 
# the use of String repeat() method
  
# Create a repetition of string "gfg"
# with 3 times of repetition.
println(repeat("gfg", 3))
  
# Create a repetition of character "a"
# with 4 times of repetition.
println(repeat("a", 4))
  
# Create a repetition of string "Geeks"
# with 2 times of repetition.
println(repeat("Geeks", 2))
  
# Create a repetition of string "@#"
# with 3 times of repetition.
println(repeat("@#", 3))

輸出:

gfggfggfg
aaaa
GeeksGeeks
@#@#@#

範例2:


# Julia program to illustrate 
# the use of String repeat() method
   
# Create a repetition of string "123"
# with 3 times of repetition.
println(repeat("123", 3))
   
# Create a repetition of string "22"
# with 4 times of repetition.
println(repeat("22", 4))
   
# Create a repetition of string "03210"
# with 2 times of repetition
println(repeat("03210", 2))

輸出:

123123123
22222222
0321003210



相關用法


注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 Get repetition of a string in Julia – repeat() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。