How do I replace a character at a particular index in JavaScript?

In JavaScript, strings are immutable, which means the best you can do is to create a new string with the changed content and assign the variable to point to it. You’ll need to define the replaceAt() function yourself: String.prototype.replaceAt = function(index, replacement) { return this.substring(0, index) + replacement + this.substring(index + replacement.length); } And use … Read more

Fastest method to replace all instances of a character in a string [duplicate]

The easiest would be to use a regular expression with g flag to replace all instances: str.replace(/foo/g, “bar”) This will replace all occurrences of foo with bar in the string str. If you just have a string, you can convert it to a RegExp object like this: var pattern = “foobar”, re = new RegExp(pattern, … Read more

How can I do a recursive find/replace of a string with awk or sed?

find /home/www \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i ‘s/subdomainA\.example\.com/subdomainB.example.com/g’ -print0 tells find to print each of the results separated by a null character, rather than a new line. In the unlikely event that your directory has files with newlines in the names, this still lets … Read more

Renaming column names in Pandas

RENAME SPECIFIC COLUMNS Use the df.rename() function and refer the columns to be renamed. Not all the columns have to be renamed: df = df.rename(columns={‘oldName1’: ‘newName1’, ‘oldName2’: ‘newName2’}) # Or rename the existing DataFrame (rather than creating a copy) df.rename(columns={‘oldName1’: ‘newName1’, ‘oldName2’: ‘newName2’}, inplace=True) Minimal Code Example df = pd.DataFrame(‘x’, index=range(3), columns=list(‘abcde’)) df a b … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)