locked
remove quotes from within string RRS feed

  • Question

  • User-2132746437 posted

    I want to replace 

    "DESCRIPTION:""something"

    with

    "DESCRIPTION:something"

    I've tried

    x[i].Replace("DESCRIPTION:@\"","DESCRIPTION:");

    but it fails, am I missing a quote somewhere?

    Wednesday, May 24, 2017 3:11 PM

Answers

  • User-1838255255 posted

    Hi csharpcoder,

    According to your description and code, I notice that you put two " characters in your code, you when you use replace method, you need use it like this:

    Sample Code:

    string path = @"C:\Users\Desktop\characters.txt";
    
    string all = System.IO.File.ReadAllText(path);
    
    string a= all.Replace("DESCRIPTION:\"\"", "DESCRIPTION:");

    Best Regards,

    Eric Du

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 25, 2017 2:45 AM

All replies

  • User2103319870 posted

    if you want to remove the double quotes then You can try with the below code

    x[i].Replace("\"","");
    Wednesday, May 24, 2017 3:24 PM
  • User-2132746437 posted

    I'm looking for the actual phrase ["DESCRIPTION:""something"] and replace it with ["DESCRIPTION:something"],

    Wednesday, May 24, 2017 3:28 PM
  • User-718146471 posted

    Actually, you are close. However to help you I need more code. Please post your code as soon as you get a chance. Thanks!

    Wednesday, May 24, 2017 3:29 PM
  • User-2132746437 posted
      string all = System.IO.File.ReadAllText(strContent);
                   string[] lines = all.Split(new string[] { "\"@\",", ",\"$\"" }, StringSplitOptions.RemoveEmptyEntries);
                   lines = lines.Skip(1).ToArray();
                   
                    for (int i = 0; i < lines.Length; i++)
                    {
                        string x = lines[i];
                        lines[i].Replace("DESCRIPTION:\"", "DESCRIPTION:"); 
                        string[] t = x.Split('"');
                        Console.WriteLine(t[1]);
                     } 

    Wednesday, May 24, 2017 3:35 PM
  • User-1838255255 posted

    Hi csharpcoder,

    According to your description and code, I notice that you put two " characters in your code, you when you use replace method, you need use it like this:

    Sample Code:

    string path = @"C:\Users\Desktop\characters.txt";
    
    string all = System.IO.File.ReadAllText(path);
    
    string a= all.Replace("DESCRIPTION:\"\"", "DESCRIPTION:");

    Best Regards,

    Eric Du

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 25, 2017 2:45 AM