Click here to Skip to main content
15,910,234 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all

How do i Remove "\"," " character from following string :

"\"status\":\"ok\""


What I have tried:

I use following code , but when run the Result is :

"status":"ok";

but i need :
status:ok

code:
string s = arr[i].Replace("'\\'", " ")
Posted
Updated 21-Jun-17 11:54am
v2

string s = arr[i].Replace("\"", "")
 
Share this answer
 

Sitecore's solution is correct. It looks like you are getting escape characters in your strings. If you want to exclude all characters that are not alphanumeric or ':' you can use the Regex class like this


C#
string testString = "\"status\":\"ok\"";
var regex = new Regex("[^a-zA-Z0-9 :]");
string cleanedString = regex.Replace(testString, "");
Console.WriteLine(cleanedString);
Console.ReadLine();

What it is doing is matching all characters that are not a-z,A-Z,0-9 or : and replacing each with an empty string.

 
Share this answer
 
v2
You need to understand escape chars and literals in C#.
Escaping in C#: characters, strings, string formats, keywords, identifiers[^]

Depending on where a string come from, user input, external file, literal in code, literal in executable, the end result is not the same.
if you have "\"status\":\"ok\"" in source code, you will have "status":"ok" in executable.

Solution is probably what you need to solve this problem.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900