How to ignore case in String.replace

Use a regular expression: var regex = new Regex( “camel”, RegexOptions.IgnoreCase ); var newSentence = regex.Replace( sentence, “horse” ); Of course, this will also match words containing camel, but it’s not clear if you want that or not. If you need exact matches you can use a custom MatchEvaluator. public static class Evaluators { public … Read more

Remove whitespace and line breaks between HTML elements using jQuery

I tried the technique that user76888 laid out and it worked nicely. I packaged it into a jQuery plugin for convenience, and thought the community might enjoy it, so here: jQuery.fn.cleanWhitespace = function() { this.contents().filter( function() { return (this.nodeType == 3 && !/\S/.test(this.nodeValue)); }) .remove(); return this; } To use this, just include it in … Read more

camelCase to underscore in vi(m)

You might want to try out the Abolish plugin by Tim Pope. It provides a few shortcuts to coerce from one style to another. For example, starting with: MixedCase Typing crc [mnemonic: CoeRce to Camelcase] would give you: mixedCase Typing crs [mnemonic: CoeRce to Snake_case] would give you: mixed_case And typing crm [mnemonic: CoeRce to … Read more

Perl: Use s/ (replace) and return new string [duplicate]

require 5.013002; # or better: use Syntax::Construct qw(/r); print “bla: “, $myvar =~ s/a/b/r, “\n”; See perl5132delta: The substitution operator now supports a /r option that copies the input variable, carries out the substitution on the copy and returns the result. The original remains unmodified. my $old = ‘cat’; my $new = $old =~ s/cat/dog/r; … Read more

JS. How to replace html element with another element/text, represented in string?

As the Jquery replaceWith() code was too bulky, tricky and complicated, here’s my own solution. =) The best way is to use outerHTML property, but it is not crossbrowsered yet, so I did some trick, weird enough, but simple. Here is the code var str=”<a href=”http://www.com”>item to replace</a>”; //it can be anything var Obj = … Read more