Open In App
Related Articles

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

Improve Article
Improve
Save Article
Save
Like Article
Like

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: 
 

  • s::AbstractString: Specified string.
  • pattern=>Word: Pattern is searched from the given sentence and then that pattern is replaced with the word.
  • count::Integer: It is a number that is the count of specified pattern available in the sentence.

Returns: It returns a new sentence with replaced words. 
 
Example 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"))


Output: 
 

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


Output: 
 

 

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 23 Feb, 2021
Like Article
Save Article
Similar Reads