-3

I'm replacing some characters to empty. But whatever I try, I can't replace the doube quotes.

What I try

deger1 = deger1.Replace("""", "");
deger1 = deger1.Replace("\"", "");
deger1 = deger1.Replace(@"""", "");
deger1 = Regex.Replace(deger1, "\"[^\"]*\"", string.Empty);

Some of these getting error. But none of these work.

I will use it for url rewrite. I'm getting "Illegal characters in path." error.

http://www.dinivideolar.com/video/400/muhammede-muhammede-%22aleyhissel%C3%A2m%22-muziksiz-ilahi

Hakkı
  • 811
  • 2
  • 13
  • 23
  • are you sure deger1 = deger1.Replace("\"", ""); isn't working? Can you provide an example of the string you are working on? – user1666620 Jul 09 '14 at 11:09
  • 3
    Use UrlEncode instead http://msdn.microsoft.com/en-us/library/zttxte6w%28v=vs.110%29.aspx Otherwise you will just run into another illegal characters error later – adrianm Jul 09 '14 at 11:10
  • 3
    Could you show us your entry string ! – Perfect28 Jul 09 '14 at 11:11
  • Debug your code step by step to find why there are no quotes on your string at the first place, but some other encoding characters – Aristos Jul 09 '14 at 11:13
  • you can either try with deger1.Replace("\"", ""); or corrected deger1.Replace(@""", ""); – Alok Jul 09 '14 at 11:15
  • Do you need to change asp.net requestValidationMode etc.? http://stackoverflow.com/questions/2087246/howto-allow-illegal-characters-in-path – mtmk Jul 09 '14 at 11:17
  • I tried this one deger1 = deger1.Replace(@""", ""); and I get newline in constant error. – Hakkı Jul 09 '14 at 11:18
  • try string deger1="hello i am \"\"coder\" "; deger1 = deger1.Replace("\"\"", ""); –  Jul 09 '14 at 11:20
  • string=> hello i am ""coder" output=> hello i am coder" –  Jul 09 '14 at 11:21
  • @Ksv3n string is muhammede-muhammede-"aleyhisselâm"-muziksiz-ilahi I wrote url. – Hakkı Jul 09 '14 at 11:23
  • provide sample input and expected output.I think your question title and requirement are not matching. –  Jul 09 '14 at 11:26
  • @JayeshBhanderi my title and requirement totaly match. I want to remove quote but its not working. – Hakkı Jul 09 '14 at 11:27
  • okei.. Be calm. Can you please provide your expected output of above input? –  Jul 09 '14 at 11:29
  • sir my string is "muhammede-muhammede-"aleyhisselâm"-muziksiz-ilahi" i just want to remove doube quotes and its not working. – Hakkı Jul 09 '14 at 11:31

2 Answers2

2

below code working fine.....

void Main()
{
 string deger1="\"muhammede-muhammede-\"aleyhisselâm\"-muziksiz-ilahi\"" ;

 Console.Write(deger1);


 deger1 = deger1.Replace("\"", "");

 Console.Write(deger1);
}

Result:

"muhammede-muhammede-"aleyhisselâm"-muziksiz-ilahi"

muhammede-muhammede-aleyhisselâm-muziksiz-ilahi

enter image description here

  • thank you but i stored the string without backslash. like this muhammede-muhammede-"aleyhisselâm"-muziksiz-ilahi not like this muhammede-muhammede-\"aleyhisselâm\"-muziksiz-ilahi do you have any tricks to put backslash before double quotes? – Hakkı Jul 09 '14 at 11:41
  • can you place your code snippet here because i can't get it how you input that string and storing it. –  Jul 09 '14 at 11:44
0
public string seoyap(String deger1)
{
    deger1 = deger1.ToLower();
    deger1 = deger1.Replace(@"""", "\"");
    deger1 = deger1.Replace("ı", "i");
    deger1 = deger1.Replace("ö", "o");
    deger1 = deger1.Replace("ç", "c");
    deger1 = deger1.Replace("ğ", "g");
    deger1 = deger1.Replace("ü", "u");
    deger1 = deger1.Replace("ş", "s");
    deger1 = deger1.Replace("  ", " ");
    deger1 = deger1.Replace(" ", "-");
    deger1 = deger1.Replace("---", "-");
    deger1 = deger1.Replace("(", "");
    deger1 = deger1.Replace(")", "");
    deger1 = deger1.Replace(".", "");
    deger1 = deger1.Replace("|", "");
    deger1 = deger1.Replace("'", "");
    deger1 = deger1.Replace(",", "");
    deger1 = deger1.Replace("[", "");
    deger1 = deger1.Replace("]", "");

    deger1 = deger1.Replace("\"", "");

    //deger1 = Regex.Replace(deger1, "\"[^\"]*\"", string.Empty);

    return deger1;
}

And in my repater I'm using this <%# seoyap(Convert.ToString(Eval("baslik"))) %>

Hakkı
  • 811
  • 2
  • 13
  • 23