Linked Questions

-2 votes
1 answer
97 views

Remove text from the environment arguments in c# [duplicate]

I want to remove certain text from the Args, if the args contain that text. args[1] = "C:\Users\Public\Roaming\Intel\Wireless\Settings\guids.xml" I want to remove "\guids.xml" if the args[1] ...
Sudha Vuppala's user avatar
401 votes
15 answers
631k views

How can I replace every occurrence of a String in a file with PowerShell?

Using PowerShell, I want to replace all exact occurrences of [MYID] in a given file with MyValue. What is the easiest way to do so?
amateur's user avatar
  • 44.8k
315 votes
16 answers
131k views

Is there an alternative to string.Replace that is case-insensitive?

I need to search a string and replace all occurrences of %FirstName% and %PolicyAmount% with a value pulled from a database. The problem is the capitalization of FirstName varies. That prevents me ...
Aheho's user avatar
  • 12.8k
40 votes
7 answers
37k views

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.Replace is the fastest way of doing it. I just care about the ...
Yannis's user avatar
  • 6,187
25 votes
1 answer
8k views

Handling regex escape replacement text that contains the dollar character

string input = "Hello World!"; string pattern = "(World|Universe)"; string replacement = "$1"; string result = Regex.Replace(input, pattern, replacement); Having the following example, the result ...
Matthew's user avatar
  • 26k
1 vote
2 answers
2k views

What is the best practice to resolve placeholders in a plain text?

I need to resolve a huge load of placeholders (about 250) in a plain text. A placeholder is defined as %ThisIsAPlaceholder%, an example would be %EmailSender%. Now it's gets a bit creepy: the code ...
Dominic Sauder's user avatar
-1 votes
3 answers
1k views

string.replace() not working with xml string

I have read all similar questions and acted accordingly. But still can't figure out what's wrong with my code. This is my code, super simple. (I know this isn't valid XML. It's just for the example). ...
Uri Klar's user avatar
  • 4,008
-2 votes
1 answer
365 views

C# replace a certain word in string except for any urls

I have a large string value and I am trying to find the best way to replace a certain text value out of it without changing any values in a URL. For instance lets say I want to replace the word "...
jsg's user avatar
  • 1,264
0 votes
0 answers
485 views

How do I replace a string with case insensitive search?

In VB6, I could say: s = Replace(s, "Find", "Replace", vbTextCompare) In VB.NET, there is only String.Replace(uFind, uReplace) which would mean binary compare, I guess. Is there ...
tmighty's user avatar
  • 11.5k
0 votes
1 answer
191 views

Add two Replace on the same Regex at the same time - Do two different things

My problem is that when I for example add a point more like it needs replacing. Then it comes up with this error: cannot convert from string to System.stringComparison If I thus comment on the last ...
j. Petersen's user avatar
0 votes
3 answers
152 views

Insert at index of search term substring

I am trying to highlight search terms in display results. Generally it works OK based on code found here on SO. My issue with it is that it replaces the substring with the search term, i.e. in this ...
Darkloki's user avatar
  • 686