Replace a substring with another string in Julia - replace() Method Last Updated : 12 Jul, 2025 Comments Improve Suggest changes Like Article Like Report 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: Comment More infoAdvertise with us Next Article Get a substring of specified length from a string in Julia - SubString() Method K Kanchan_Ray Follow Improve Article Tags : Julia Similar Reads Get repetition of a string in Julia - repeat() Method The repeat() is an inbuilt function in julia which is used to return a string which is the repetition of specified string with specified number of times. Syntax: repeat(String::AbstractString, r::Integer) Parameters: String: Specified string or character r::Integer: Specified number of times Returns 2 min read Replacing elements of a collection in Julia - replace() and replace!() Methods The replace() is an inbuilt function in julia which is used to return a copy of the specified array with different types of replacement. These all operations are illustrated with below examples. Syntax: replace(A, old_new::Pair...; count::Integer) or replace(new::Function, A; count::Integer) Paramet 3 min read Remove a single trailing newline from a string in Julia - chomp() Method The chomp() is an inbuilt function in julia which is used to remove a single trailing newline from a string. Syntax: chomp(s::AbstractString) Parameters: s::AbstractString: Specified string. Returns: It returns a new string after removal of a single trailing newline. Example 1: Python # Julia progra 1 min read Check if string starts with a specified prefix in Julia - startswith() Method The startswith() is an inbuilt function in julia which is used to return true if the specified string start with the specified prefix else return false. Syntax: startswith(s::AbstractString, prefix::AbstractString) Parameters: s::AbstractString: Specified string. prefix::AbstractString: Specified pr 1 min read Get a substring of specified length from a string in Julia - SubString() Method The SubString() is an inbuilt function in julia which is used to return a part of the specified parent string s within range i:j or r, where i, j and r is given as the parameter. Syntax: SubString(string::AbstractString, i::Integer, j::Integer) or SubString(string::AbstractString, r::UnitRange) Para 2 min read Get a substring of specific size from end of a string in Julia - last() Method The last() is an inbuilt function in julia which is used to return a string consisting of the last n characters of the specified string, where n will be passed as parameter. Syntax: last(s::AbstractString, n::Integer) Parameters: s::AbstractString: Specified string. n::Integer: Specified integer val 1 min read Like