replace
Replacing illegal character in fileName
You need to replace everything but [a-zA-Z0-9.-]. The ^ within the brackets stands for “NOT”. myString = myString.replaceAll(“[^a-zA-Z0-9\\.\\-]”, “_”);
Replace element in List with scala
If you want to replace index 2, then list.updated(2,5) // Gives 1 :: 2 :: 5 :: 4 :: Nil If you want to find every place where there’s a 2 and put a 5 in instead, list.map { case 2 => 5; case x => x } // 1 :: 5 :: 3 :: … Read more
Find and replace whole words in vim
You can use \< to match the beginning of a word and \> to match the end: %s/\<word\>/newword/g
`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
How do I replace all occurrences of a string in JavaScript?
As of August 2020: Modern browsers have support for the String.replaceAll() method defined by the ECMAScript 2021 language specification. For older/legacy browsers: function escapeRegExp(string) { return string.replace(/[.*+?^${}()|[\]\\]/g, ‘\\$&’); // $& means the whole matched string } function replaceAll(str, find, replace) { return str.replace(new RegExp(escapeRegExp(find), ‘g’), replace); } Here is how this answer evolved: str = … Read more
Fast replacement of values in a numpy array
I believe there’s even more efficient method, but for now, try from numpy import copy newArray = copy(theArray) for k, v in d.iteritems(): newArray[theArray==k] = v Microbenchmark and test for correctness: #!/usr/bin/env python2.7 from numpy import copy, random, arange random.seed(0) data = random.randint(30, size=10**5) d = {4: 0, 9: 5, 14: 10, 19: 15, 20: … Read more
Replace Into Query Syntax
As the documentation says: REPLACE works exactly like INSERT, except that if an old row in the table has the same value as a new row for a PRIMARY KEY or a UNIQUE index, the old row is deleted before the new row is inserted.
Replace substring of NSAttributedString with another NSAttributedString
Convert your attributed string into an instance of NSMutableAttributedString. The mutable attributed string has a mutableString property. According to the documentation: “The receiver tracks changes to this string and keeps its attribute mappings up to date.” So you can use the resulting mutable string to execute the replacement with replaceOccurrencesOfString:withString:options:range:.