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


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。