-2

I have a string DisplayName which has value as "Vinny' Direct Reports". I am trying to replace "'"with "-"in string as it failing to get ingested into my Data Source.

Below is the code where I am trying to replace.

if (DisplayName.Contains("'", StringComparison.OrdinalIgnoreCase) == true)
        {
            DisplayName.Replace("'", "-").Replace("\"", "-");
            Console.WriteLine(DisplayName);
        }
Vinny
  • 461
  • 1
  • 5
  • 18
  • 1
    Replace returns a string, so you will need to assign the output back to your variable – hijinxbassist Mar 03 '22 at 00:50
  • I just realized that https://stackoverflow.com/questions/14442577/string-replace-not-replacing-apostrophe already has answer. Thanks a ton. I am good now. – Vinny Mar 03 '22 at 01:01
  • @LarsTech Why is `Replace` not a method? Saying that `Replace` is not a method seems wrong even with a very conservative view of the defintions of two terms. – tymtam Mar 03 '22 at 01:39

1 Answers1

0

Change this:

DisplayName.Replace("'", "-").Replace("\"", "-");

To this:

DisplayName = DisplayName.Replace("'", "-").Replace("\"", "-");
CorrieJanse
  • 2,374
  • 1
  • 6
  • 23
  • I just realized that https://stackoverflow.com/questions/14442577/string-replace-not-replacing-apostrophe already has answer. Thanks a ton. I am good now. – Vinny Mar 03 '22 at 01:01