I want to replace all phrases $br$
in the string for the character '\n'
.
I write the following code: str = string.gsub("String 1 $br$ String 2", "$br$", "\n")
.
But this does not work and displays the string String 1 $br$ String 2
. What am I doing wrong?
gsub (s, pattern, repl [, n]) Returns a copy of s in which all (or the first n , if given) occurrences of the pattern have been replaced by a replacement string specified by repl , which can be a string, a table, or a function. gsub also returns, as its second value, the total number of matches that occurred.
#gsub is not only slower, but it also requires an extra effort for the reader to 'decode' the arguments.
To remove a character in an R data frame column, we can use gsub function which will replace the character with blank. For example, if we have a data frame called df that contains a character column say x which has a character ID in each value then it can be removed by using the command gsub("ID","",as.
You need to escape the $
character since it represents the end of line.
str = string.gsub("String 1 $br$ String 2", "%$br%$", "\n")
If you want to grab the whitespace around $br$
as well:
str = string.gsub("String 1 $br$ String 2", "%s*%$br%$%s*", "\n")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With