tagged [replace]

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

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

How can I use a dictionary to do multiple search-and-replace operations?

How can I use a dictionary to do multiple search-and-replace operations? I have to replace text like "north", "south", etc. with "N", "S" etc. in address fields. I thought of making a dictionary to ho...

4 Feb at 18:3

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

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

Remove multiple whitespaces

Remove multiple whitespaces I'm getting `$row['message']` from a MySQL database and I need to remove all whitespace like `\n` `\t` and so on. should be formatted to: I tried: b

Java how to replace 2 or more spaces with single space in string and delete leading and trailing spaces

Java how to replace 2 or more spaces with single space in string and delete leading and trailing spaces Looking for quick, simple way in Java to change this string to something that looks like this wh...

4 Sep at 05:0

How to replace space with comma using sed?

How to replace space with comma using sed? I would like to replace the empty space between each and every field with comma delimiter.Could someone let me know how can I do this.I tried the below comma...

24 Jun at 05:59

regex string replace

regex string replace I am trying to do a basic string replace using a regex expression, but the answers I have found do not seem to help - they are directly answering each persons unique requirement w...

4 May at 08:59

How to delete all instances of a character in a string in python?

How to delete all instances of a character in a string in python? How do I delete all the instances of a character in this string? Here is my code: However, if I run this, this is what happens: ``` >>...

5 Mar at 02:23

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

Replace CRLF using powershell

Replace CRLF using powershell Here is my powershell script: ``` $original_file ='C:\Users\abc\Desktop\File\abc.txt' (Get-Content $original_file) | Foreach-Object { $_ -replace "'", "2"` -replace '2', ...

22 Feb at 04:19

How do I perform a Perl substitution on a string while keeping the original?

How do I perform a Perl substitution on a string while keeping the original? In Perl, what is a good way to perform a replacement on a string using a regular expression and store the value in a differ...

1 Aug at 18:12

How to replace an entire line in a text file by line number

How to replace an entire line in a text file by line number I have a situation where I want a bash script to replace an entire line in a file. The line number is always the same, so that can be a hard...

19 Apr at 21:54

How do I replace an actual asterisk character (*) in a Regex expression?

How do I replace an actual asterisk character (*) in a Regex expression? I have a statement: I have a string such as I want to search and replace it with so when I am done the string contains this: My...

10 May at 22:13

Replace/Remove characters that do not match the Regular Expression (.NET)

Replace/Remove characters that do not match the Regular Expression (.NET) I have a regular expression to validate a string. But now I want to remove all the characters that do not match my regular exp...

27 May at 15:49

Replacing multiple characters in a string in c# by a one liner

Replacing multiple characters in a string in c# by a one liner What I'm wondering of is whether it is possible to replace multiple characters in a string (lets say, the &, | and $ characters for examp...

30 Jul at 08:14

How to remove a pattern from a string using Regex

How to remove a pattern from a string using Regex I want to find paths from a string and remove them, e.g.: ``` string1 = "'c:\a\b\c'!MyUDF(param1, param2,..) + 'c:\a\b\c'!MyUDF(param3, param4,..)..."...

10 Feb at 22:43

Using tr to replace newline with space

Using tr to replace newline with space Have output from `sed`: Those two strings should be merged into one and separated with space like: Two strings are pipelined to `tr` in order to replace newline ...

7 Mar at 01:53

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 to remove spaces and newlines in a string

How to remove spaces and newlines in a string sorry if they are not very practical for C # Asp.Net, I hope to make me understand I have this situation I would make sure that the string does not contai...

9 Jan at 10:19

How to use named groups when performing a Regex.Replace()

How to use named groups when performing a Regex.Replace() How do I use named captures when performing Regex.Replace? I have gotten this far and it does what I want but not in the way I want it: ``` [T...

18 Oct at 19:19

C# String replace with dictionary

C# String replace with dictionary I have a string on which I need to do some replacements. I have a `Dictionary` where I have search-replace pairs defined. I have created following extension methods t...

5 Aug at 07:58

Turning a single quote into an escaped single quote within a string

Turning a single quote into an escaped single quote within a string It pains me to ask this, but, for some reason I have not been able to get this to work (it's late in the day, yes, that's my excuse)...

23 May at 22:10

Quickly replace first line of large file

Quickly replace first line of large file I have many large csv files (1-10 gb each) which I'm importing into databases. For each file, I need to replace the 1st line so I can format the headers to be ...

6 Dec at 16:39