Questions tagged [replace]

Replacing is the action of searching a string for a sub-string and replacing it with a different string.

Replacing is the action of searching a string (the haystack) for a sub-string (the needle) and replacing it with a different string.

for example, replacing all 'l' within 'Hello' with 'y', would result in 'Heyyo'.

27903 questions
127
votes
2 answers

Find and replace globally in Sublime Text 2 (all files and in all directories)

Is there a way to find and replace a text string automatically in all folder's files?
itsme
  • 48,972
  • 96
  • 224
  • 345
126
votes
8 answers

Replacing few values in a pandas dataframe column with another value

I have a pandas dataframe df as illustrated below: BrandName Specialty A H B I ABC J D K AB L I want to replace 'ABC' and 'AB' in column BrandName by 'A'. Can someone help with this?
Pulkit Jha
  • 1,709
  • 3
  • 12
  • 18
125
votes
11 answers

Linux - Replacing spaces in the file names

I have a number of files in a folder, and I want to replace every space character in all file names with underscores. How can I achieve this?
Mithun Sreedharan
  • 49,883
  • 70
  • 181
  • 236
123
votes
8 answers

Replace string within file contents

How can I open a file, Stud.txt, and then replace any occurences of "A" with "Orange"?
Joey
  • 1,297
  • 2
  • 8
  • 5
122
votes
10 answers

Replace word with contents of paste buffer?

I need to do a bunch of word replacements in a file and want to do it with a vi command, not an EX command such as :%s///g. I know that this is the typical way one replaces the word at the current cursor position: cw but is there a way to…
plong
  • 1,723
  • 3
  • 14
  • 14
121
votes
15 answers

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?
Nirmal
119
votes
21 answers

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 function that achieves this in .
Eun-Gyu Kim
119
votes
10 answers

Replace invalid values with None in Pandas DataFrame

Is there any method to replace values with None in Pandas in Python? You can use df.replace('pre', 'post') and can replace a value with another, but this can't be done if you want to replace with None value, which if you try, you get a strange…
Blaszard
  • 30,954
  • 51
  • 153
  • 233
117
votes
11 answers

Java Replacing multiple different substring in a string at once (or in the most efficient way)

I need to replace many different sub-string in a string in the most efficient way. is there another way other then the brute force way of replacing each field using string.replace ?
Yossale
  • 14,165
  • 22
  • 82
  • 109
116
votes
4 answers

Remove all multiple spaces in Javascript and replace with single space

How can I automatically replace all instances of multiple spaces, with a single space, in Javascript? I've tried chaining some s.replace but this doesn't seem optimal. I'm using jQuery as well, in case it's a builtin functionality.
Alex
  • 75,813
  • 86
  • 255
  • 348
115
votes
13 answers

Using jQuery to replace one tag with another

Goal: Using jQuery, I'm trying to replace all the occurrences of: ... with:
 ... 
My solution: I got as far as the following, $('code').replaceWith( "
" + $('code').html() + "
" ); The problem with my…
jon
  • 5,961
  • 8
  • 35
  • 43
114
votes
3 answers

JavaScript replace \n with

var messagetoSend = $.trim(document.getElementById("msgText").value); messagetoSend = messagetoSend.replace("\n", "
"); alert(messagetoSend); Given input: Line 1 Line 2 Line 3 This alerts: Line 1
Line 2 Line 3 When I expect…
Tom Gullen
  • 61,249
  • 84
  • 283
  • 456
113
votes
10 answers

How to add multiple arguments to my custom template filter in a django template?

Here's my custom filter: from django import template register = template.Library() @register.filter def replace(value, cherche, remplacement): return value.replace(cherche, remplacement) And, here are the ways I tried using it in my template…
bchhun
  • 18,116
  • 8
  • 28
  • 31
112
votes
10 answers

Case-insensitive search and replace with sed

I'm trying to use SED to extract text from a log file. I can do a search-and-replace without too much trouble: sed 's/foo/bar/' mylog.txt However, I want to make the search case-insensitive. From what I've googled, it looks like appending i to the…
Craig Walker
  • 49,871
  • 54
  • 152
  • 212
110
votes
8 answers

Replace all particular values in a data frame

Having a data frame, how do I go about replacing all particular values along all rows and columns. Say for example I want to replace all empty records with NA's (without typing the positions): df <- data.frame(list(A=c("", "xyz", "jkl"), B=c(12, "",…
zxzak
  • 8,985
  • 4
  • 27
  • 25