Javascript – Replacing the escape character in a string literal

If it’s a literal, you need to escape the backslashes before Javascript sees them; there’s no way around that. var newpath=”file:///C:\\funstuff\\buildtools\\viewer.html”; window.location = newpath; If newpath is getting its value from somewhere else, and really does contain single backslashes, you don’t need to double them up; but if you really wanted to for some reason, … Read more

Find and replace within a text file using Python

How about this: sed -i ‘s/;/ /g’ yourBigFile.txt This is not a Python solution. You have to start this in a shell. But if you use Notepad, I guess you are on Windows. So here a Python solution: f1 = open(‘yourBigFile.txt’, ‘r’) f2 = open(‘yourBigFile.txt.tmp’, ‘w’) for line in f1: f2.write(line.replace(‘;’, ‘ ‘)) f1.close() f2.close()

Replace Last Occurrence of a character in a string [duplicate]

This should work: String replaceLast(String string, String substring, String replacement) { int index = string.lastIndexOf(substring); if (index == -1) return string; return string.substring(0, index) + replacement + string.substring(index+substring.length()); } This: System.out.println(replaceLast(“\”Position, fix, dial\””, “\””, “\\\””)); Prints: “Position, fix, dial\” Test.

Find and replace in a file

You could read the entire file in with file_get_contents(), perform a str_replace(), and output it back with file_put_contents(). Sample code: <?php $path_to_file=”path/to/the/file”; $file_contents = file_get_contents($path_to_file); $file_contents = str_replace(“\nH”, “,H”, $file_contents); file_put_contents($path_to_file, $file_contents); ?>