Open In App

Replace a substring with another string in Julia – replace() Method

The replace() is an inbuilt function in julia that is used to replace a word or character with the specified string or character.
 

Syntax: 



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

Parameters: 
 

Returns: It returns a new sentence with replaced words. 
 
Example 1: 






# 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"))

Output: 
 

Example 2: 




# 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))

Output: 
 

 

Article Tags :