a=("bcz following are bcz graphical (non-control) characters defined by
ISO 8859-1. Descriptions in words aren't all that helpful,
but they're bcz best we can do in text.
A graphics file illustrating
bcz character set should be available from bcz same archive as this
file.")
#Using stringr library
library(stringr)#package stringr to manipulate string
stringr = str_replace_all(string=a,pattern="bcz",replacement = "because")
stringr
#Using gsub
test <- "high five to edwisor bcz they are doing good work"
gsub("bcz", "because", test)
Python Code:
In Python same can be achieved by using string.replace() function.

#Here's our text
a = ('bcz following are bcz graphical (non-control) characters defined bcz')
a
'bcz following are bcz graphical (non-control) characters defined bcz'
#Using replace method
#The syntax of replace() is:str.replace(old, new [, count])
a = a.replace('bcz', 'because')
a
'because following are because graphical (non-control) characters defined because'
#Replace using dictionary if there are more than one word to replace
#Building dictionary consisting of key as word to match and value as word to replace
dic = {'bcz':'because'}
text = ('bcz following are bcz graphical (non-control) characters defined bcz')


You've reached the end of your free preview.
Want to read all 3 pages?
- Fall '19
- Data Mining, Natural Language Processing, Regular expression, stringr