tagged [replace]

Adding backslashes without escaping

Adding backslashes without escaping I need to escape a `&` (ampersand) character in a string. The problem is whenever I `string = string.replace ('&', '\&')` the result is `'\\&'`. An extra backslash ...

8 Jul at 04:15

Remove specific characters from a string in Python

Remove specific characters from a string in Python I'm trying to remove specific characters from a string using Python. This is the code I'm using right now. Unfortunately it appears to do nothing to ...

30 May at 12:32

Fastest way to replace multiple strings in a huge string

Fastest way to replace multiple strings in a huge string I'm looking for the fastest way to replace multiple (~500) substrings of a big (~1mb) string. Whatever I have tried it seems that String.Replac...

21 Apr at 06:15

Replace the string of special characters in C#

Replace the string of special characters in C# My requirement is: > I have to replace some special characters like * ' " , _ & # ^ @ with `string.Empty`, and I have to replace blank spaces with `-`. T...

29 Mar at 18:0

How can I perform a str_replace in JavaScript, replacing text in JavaScript?

How can I perform a str_replace in JavaScript, replacing text in JavaScript? I want to use `str_replace` or its similar alternative to replace some text in JavaScript. should give ``` this is some sam...

15 Mar at 12:25

How can I remove a character from a string using JavaScript?

How can I remove a character from a string using JavaScript? I am so close to getting this, but it just isn't right. All I would like to do is remove the character `r` from a string. The problem is, t...

11 Dec at 07:58

What function is to replace a substring from a string in C?

What function is to replace a substring from a string in C? Given a (`char *`) string, I want to find all occurrences of a substring and replace them with an alternate string. I do not see any simple ...

24 Jul at 19:8

C# replace string in string

C# replace string in string Is it possible to replace a substring in a string without assigning a return value? I have a string: And I want to replace the substring `[REPLACE]` with something else: Th...

20 Jul at 18:15

C# string replace

C# string replace I want to replace `","` with a `;` in my string. For example: Change > "Text","Text","Text", to this: > "Text;Text;Text", I've been trying the `line.replace( ... , ... )`, but can't ...

19 Jul at 17:45

Regex replace multiple groups

Regex replace multiple groups I would like to use regular expressions to replace multiple groups with corresponding replacement string. Replacement table: - `"&"``"__amp"`- `"#"``"__hsh"`- `"1"``"5"`-...

9 Jun at 11:42

Replace and overwrite instead of appending

Replace and overwrite instead of appending I have the following code: where I'd like to replace the old content that's in the file with the new content

16 Feb at 19:44

How does MatchEvaluator in Regex.Replace work?

How does MatchEvaluator in Regex.Replace work? This is the input string `23x * y34x2`. I want to insert `" * "` (star surrounded by whitespaces) after every number followed by letter, and after every ...

21 Jan at 10:0

Strip Leading and Trailing Spaces From Java String

Strip Leading and Trailing Spaces From Java String Is there a convenience method to strip any leading or trailing spaces from a Java String? Something like: Result: `myString.replace(" ","")` would re...

23 Sep at 19:15

Best way to replace multiple characters in a string?

Best way to replace multiple characters in a string? I need to replace some characters as follows: `&` ➔ `\&`, `#` ➔ `\#`, ... I coded as follows, but I guess there should be some better way. Any hint...

4 Sep at 15:7

String replace method is not replacing characters

String replace method is not replacing characters I have a sentence that is passed in as a string and I am doing a replace on the word "and" and I want to replace it with " ". And it's not replacing t...

13 Jul at 12:21

How do I find and replace all occurrences (in all files) in Visual Studio Code?

How do I find and replace all occurrences (in all files) in Visual Studio Code? I can't figure out how to find and replace all occurrences of a word in different files using Visual Studio Code version...

10 Jul at 10:32

Transform title into dashed URL-friendly string

Transform title into dashed URL-friendly string I would like to write a C# method that would transform any title into a URL friendly string, similar to what Stack Overflow does: - - - I'm thinking of ...

9 Jun at 17:58

How to replace a character by a newline in Vim

How to replace a character by a newline in Vim I'm trying to replace each `,` in the current file by a new line: But it inserts what looks like a `^@` instead of an actual newline. The file is not in ...

12 Apr at 13:18

Find and replace with sed in directory and sub directories

Find and replace with sed in directory and sub directories I run this command to find and replace all occurrences of 'apple' with 'orange' in all files in root of my site: But it doesn't go through su...

9 Mar at 15:51

Replace specific characters within strings

Replace specific characters within strings I would like to remove specific characters from strings within a vector, similar to the feature in Excel. Here are the data I start with: ``` group

Replace all occurences of a string from a string array

Replace all occurences of a string from a string array I have a string array like: I would like to replace all ones with zero at once. Then items should be: `{"zero","two","three","zero","two","zero"}...

8 Jan at 22:13

How do I replace the *first instance* of a string in .NET?

How do I replace the *first instance* of a string in .NET? I want to replace the first occurrence in a given string. How can I accomplish this in .NET?

15 Sep at 21:21

Fastest method to replace all instances of a character in a string

Fastest method to replace all instances of a character in a string What is the fastest way to replace all instances of a string/character in a string in JavaScript? A `while`, a `for`-loop, a regular ...

5 Sep at 16:43

Find and replace - Add carriage return OR Newline

Find and replace - Add carriage return OR Newline In the case of following string to be parsed. I want to replace the `~~?` with a `carriage return` Replacing with `\n` just adds the string `"\n"` How...

Replace None with NaN in pandas dataframe

Replace None with NaN in pandas dataframe I have table `x`: I want to replace python None with pandas NaN. I tried: But I got: ``` TypeError: 'regex' must be a string or a compiled regular expression ...

14 May at 03:8