replace
How to convert back-slashes to forward-slashes?
I recently found this and thought worth sharing: import os path = “C:\\temp\myFolder\example\\” newPath = path.replace(os.sep, “https://stackoverflow.com/”) print(newPath) # -> C:/temp/myFolder/example/
c# Fastest way to remove extra white spaces
The fastest way? Iterate over the string and build a second copy in a StringBuilder character by character, only copying one space for each group of spaces. The easier to type Replace variants will create a bucket load of extra strings (or waste time building the regex DFA). Edit with comparison results: Using http://ideone.com/NV6EzU, with … Read more
Remove first x number of characters from each row in a column of a Python dataframe
Use vectorised str methods to slice each string entry In [11]: d[‘Report Number’] = d[‘Report Number’].str[3:] d Out[11]: Name Report Number 0 George 1234567 1 Bill 9876543 2 Sally 4434555
Javascript and backslashes replace
Got stumped by this for ages and all the answers kept insisting that the source string needs to already have escaped backslashes in it … which isn’t always the case. Do this .. var replaced = str.replace(String.fromCharCode(92),String.fromCharCode(92,92));
Removing non-alphanumeric characters with sed
tr’s -c (complement) flag may be an option echo “Â10.41.89.50-._ ” | tr -cd ‘[:alnum:]._-‘
How to replace first occurrence of string in Java
You can use replaceFirst(String regex, String replacement) method of String.
Replace \n with [duplicate]
thatLine = thatLine.replace(‘\n’, ‘<br />’) str.replace() returns a copy of the string, it doesn’t modify the string you pass in.
replace a whole file with another file in bash
cp -f [original file] [new file] Copies the original file and overwrites the target file (hence -f which stands for “force”).
How to replace comma with a dot in the number (or any replacement) [duplicate]
As replace() creates/returns a new string rather than modifying the original (tt), you need to set the variable (tt) equal to the new string returned from the replace function. tt = tt.replace(/,/g, ‘.’) JSFiddle