remove last directory in URL
By using this code remove the last element from the Url link. url.substring(0, url.lastIndexOf(“https://stackoverflow.com/”));
By using this code remove the last element from the Url link. url.substring(0, url.lastIndexOf(“https://stackoverflow.com/”));
You can just go for String replace method.- line1 = line1.replace(“\””, “”);
There is absolutely no difference in put and replace when there is a current mapping for the wanted key. From replace: Replaces the entry for the specified key only if it is currently mapped to some value. This means that if there is already a mapping for the given key, both put and replace will … Read more
One approach that you can use on smaller files that can fit into your memory twice: $data = file(‘myfile’); // reads an array of lines function replace_a_line($data) { if (stristr($data, ‘certain word’)) { return “replacement line!\n”; } return $data; } $data = array_map(‘replace_a_line’, $data); file_put_contents(‘myfile’, $data); A quick note, PHP > 5.3.0 supports lambda functions … Read more
Use a simple list comprehension: [‘None’ if v is None else v for v in d] Demo: >>> d = [1,’q’,’3′, None, ‘temp’] >>> [‘None’ if v is None else v for v in d] [1, ‘q’, ‘3’, ‘None’, ‘temp’] Note the is None test to match the None singleton.
If you’re writing the page dynamically, you can add the last-modified timestamp to the URL: <img src=”https://stackoverflow.com/questions/321865/image.jpg?lastmod=12345678″ …
Does this work: $msgid = $_GET[‘msgid’]; $oldMessage=””; $deletedFormat=””; //read the entire string $str=file_get_contents(‘msghistory.txt’); //replace something in the file string – this is a VERY simple example $str=str_replace($oldMessage, $deletedFormat,$str); //write the entire string file_put_contents(‘msghistory.txt’, $str);
In vim, you can do :%s/^\(.*\)$/”\1″/ s/regex/replace/ is vim command for search n replace. % makes it apply throughout the file ^ and $ denotes start and end of the line respectively. (.*) captures everything in between. ( and ) needs to be escaped in vim regexes. \1 puts the captured content between two quotes.
One way is to use re.sub, that’s my preferred way. import re my_str = “hey th~!ere” my_new_string = re.sub(‘[^a-zA-Z0-9 \n\.]’, ”, my_str) print my_new_string Output: hey there Another way is to use re.escape: import string import re my_str = “hey th~!ere” chars = re.escape(string.punctuation) print re.sub(‘[‘+chars+’]’, ”,my_str) Output: hey there Just a small tip about … Read more
CSS Solution If you want to disable the effect of multiple <br> on the page, you can do it by CSS without using JavaScript: br + br { display: none; } Check the jsFiddle demo. However, this method is ideal when you are working with tags, something like this: <div>Text</div><br /><br /><br /> <div>Text</div><br /><br … Read more