xxxxxxxxxx
const p = 'The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?';
console.log(p.replace('dog', 'monkey'));
// expected output: "The quick brown fox jumps over the lazy monkey. If the dog reacted, was it really lazy?"
const regex = /Dog/i;
console.log(p.replace(regex, 'ferret'));
// expected output: "The quick brown fox jumps over the lazy ferret. If the dog reacted, was it really lazy?"
xxxxxxxxxx
'''Write a python program using functions to display every occurrence
of word “yours” in file.txt as “mine”.'''
# input
def yours_mine():
f=open('file.txt','r+')
p=f.read()
x=p.replace('yours','mine')
f.seek(0)
f.write(x)
f.close()
yours_mine()
'''file.txt'''
The life that I have
Is all that I have
And the life that I have
Is yours
The love that I have
Of the life that I have
Is yours and yours and yours.
A sleep I shall have
A rest I shall have
Yet death will be but a pause
For the peace of my years
In the long green grass
Will be yours and yours and yours
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
#output:
'''file.txt'''
''The life that I have
Is all that I have
And the life that I have
Is mine
The love that I have
Of the life that I have
Is mine and mine and mine.
A sleep I shall have
A rest I shall have
Yet death will be but a pause
For the peace of my years
In the long green grass
Will be mine and mine and mine.''
xxxxxxxxxx
laptops["screen_size"] = laptops["screen_size"].str.replace('"','')
print(laptops["screen_size"].unique())
xxxxxxxxxx
const myText = 'The weather is cold';
const newString = myText.replace('cold', 'warm');
console.log(newString); // Should print "The weather is warm"
// the replace() string function takes a string,
// replaces one substring with another, and returns
// a new string with the replacement made
xxxxxxxxxx
# use of replace() method
string = "Join our community of top freelancers"
# replace "top" with "top 1%"
print(string.replace("top", "top 1%"))
# printing the original string
print(string)
xxxxxxxxxx
string = "Hey! What's up?"
characters = "'!?"
for x in range(len(characters)):
string = string.replace(characters[x],"")
print(string)
xxxxxxxxxx
oldstring = 'I like Guru99'
newstring = oldstring.replace('like', 'love')
print(newstring)
xxxxxxxxxx
df[column_name].replace([old_value1, old_value2, old_value3], new_value)