📌  相关文章
📜  在 Julia 中用另一个字符串替换一个子字符串——replace() 方法

📅  最后修改于: 2021-11-25 04:43:01             🧑  作者: Mango

替换()是在被用于替代与指定的字符串或字符的单词或字符朱莉娅一个内置函数。

句法:

replace(s::AbstractString, pattern=>Word; count::Integer)

参数:

  • s::AbstractString:指定的字符串。
  • pattern=>Word:从给定的句子中搜索模式,然后用单词替换该模式。
  • count::Integer:它是一个数字,它是句子中可用的指定模式的计数。

返回:它返回一个带有替换词的新句子。示例 1:

Python
# Julia program to illustrate
# the use of String replace() method
 
# Getting a new sentence with replaced words
println(replace("GFG is a CS portal.", "CS" => "Computer Science"))
println(replace("GeeksforGeeks is a CS portal.", "GeeksforGeeks" => "GFG"))


Python
# Julia program to illustrate
# the use of String replace() method
 
# Getting a new sentence with replaced words
println(replace("GFG Geeks.", "GFG" => "GeeksforGeeks", count = 1))
println(replace("GFG Geeks GFG.", "GFG" => "GeeksforGeeks", count = 2))


输出:

示例 2:

Python

# Julia program to illustrate
# the use of String replace() method
 
# Getting a new sentence with replaced words
println(replace("GFG Geeks.", "GFG" => "GeeksforGeeks", count = 1))
println(replace("GFG Geeks GFG.", "GFG" => "GeeksforGeeks", count = 2))

输出: