Replace spaces with dashes and make all letters lower-case

Just use the String replace and toLowerCase methods, for example: var str = “Sonic Free Games”; str = str.replace(/\s+/g, ‘-‘).toLowerCase(); console.log(str); // “sonic-free-games” Notice the g flag on the RegExp, it will make the replacement globally within the string, if it’s not used, only the first occurrence will be replaced, and also, that RegExp will … Read more

PHP – Replace colour within image

You need to open the input file and scan each pixel to check for your chromokey value. Something like this: // Open input and output image $src = imagecreatefromJPEG(‘input.jpg’) or die(‘Problem with source’); $out = ImageCreateTrueColor(imagesx($src),imagesy($src)) or die(‘Problem In Creating image’); // scan image pixels for ($x = 0; $x < imagesx($src); $x++) { for … Read more

C# Replace bytes in Byte[]

You could program it…. try this for a start… this is however not robust not production like code yet…beaware of off-by-one errors I didn’t fully test this… public int FindBytes(byte[] src, byte[] find) { int index = -1; int matchIndex = 0; // handle the complete source array for(int i=0; i<src.Length; i++) { if(src[i] == … Read more

Replace occurrences of NSNull in nested NSDictionary

A small modification to the method can make it recursive: @interface NSDictionary (JRAdditions) – (NSDictionary *) dictionaryByReplacingNullsWithStrings; @end @implementation NSDictionary (JRAdditions) – (NSDictionary *) dictionaryByReplacingNullsWithStrings { const NSMutableDictionary *replaced = [NSMutableDictionary dictionaryWithDictionary: self]; const id nul = [NSNull null]; const NSString *blank = @””; for (NSString *key in self) { const id object = [self … Read more

Eliminate newlines in google app script using regex

It seems that in replaceText, to remove soft returns entered with Shift–ENTER, you can use \v: .replaceText(“\\v+”, “”) If you want to remove all “other” control characters (C0, DEL and C1 control codes), you may use .replaceText(“\\p{Cc}+”, “”) Note that the \v pattern is a construct supported by JavaScript regex engine, and is considered to … Read more

MySQL for replace with wildcard

Update: MySQL 8.0 has a function REGEX_REPLACE(). Below is my answer from 2014, which still applies to any version of MySQL before 8.0: REPLACE() does not have any support for wildcards, patterns, regular expressions, etc. REPLACE() only replaces one constant string for another constant string. You could try something complex, to pick out the leading … Read more

`string.replace` doesn’t change the variable [duplicate]

According to the Javascript standard, String.replace isn’t supposed to modify the string itself. It just returns the modified string. You can refer to the Mozilla Developer Network documentation for more info. You can always just set the string to the modified value: variableABC = variableABC.replace(‘B’, ‘D’) Edit: The code given above is to only replace … Read more