Replacing ' " ' in a string [duplicate] - c#

This question already has answers here:
How to replace straight quotation mark (")
(3 answers)
Closed 6 years ago.
Some string variables have a " in the data which recks with my php code. I want to take it out in my C# code before the data gets passed to php. I just can't remember the way of doing it, but I tried with this :
line.Replace(#""", "");
This is not correct in Xamarin, what is the good syntax?

I guess this would work.
line.replace("\"","");

use \ to escape it.
line.Replace("\"", "");

Related

C#: String with escaped quote ends up with three escaped characters [duplicate]

This question already has answers here:
Replace "\\" with "\" in a string in C#
(9 answers)
Escape Characters Aren't Working In Debugger (C#)
(2 answers)
How can I add \ symbol to the end of string in C#
(8 answers)
Why does .NET add an additional slash to the already existent slashes in a path?
(4 answers)
Escape sequence with "\" symbol
(4 answers)
Closed 2 years ago.
I'm struggling with escape characters in C#.
I'm saving a varchar field in a SQL Server database with a quote that needs to be escaped. So, an example could be something like that: (\"value\")
When my frontend application consume this value from API I get the value with a single escape character as i have in the DB.
The problem come up when consuming this API from C# code. For some reason this single character (\) is replaced for three of them (\\\).
After debugging the code I found that when I retrieve the data I get this:
debugging the value
When I click to check the value it seems OK:
Value into Text Visualizer
My question is why theese two extra backslashes are added and how can I get rid of them in order to get only one => (\").
Hope anyone can help me :)
Thanks!
You value should be correct. The debugger window escape the “/“, therefore it appears like escape(backslash)escape(quote).
(//)(/“)

c# regex not enough )'s [duplicate]

This question already has answers here:
Regex escape with \ or \\?
(5 answers)
Closed 4 years ago.
I'm getting the not enough )'s error, but as best I can tell I've got all the )'s in.
line getting error:
string pathFriendlyDevId = Regex.Match(device, "VEN.*(?=\\)").ToString().Replace("&", "_");
device string getting parsed:
string device = "PCI\\VEN_144D&DEV_A804&SUBSYS_A801144D&REV_00\\4&10B60712&0&00EA";
the goal here is to get everything from VEN to REV_00.
Am I missing something obvious here?
As was pointed out above, using a verbatim string such as #"VEN.*(?=\\)" did the trick

escape for "{" inside C# 6 string interpolation [duplicate]

This question already has answers here:
How to escape braces (curly brackets) in a format string in .NET
(11 answers)
Closed 5 years ago.
I am hoping to use a "{" inside a string interpolation statement but I'm having trouble finding the escape character to do it.
var val = "ERROR_STATE";
var str = $"if(inErrorState){ send 1,\"{val}\" }"
Desired output:
if(inErrorState){send 1,"ERROR_STATE"}
The simple solution is to just not use string interpolation, but I think this way of doing it is easier to read.
Type { twice to escape it:
$"if(inErrorState){{send 1, \"{val}\" }}"
BTW you can do the same with double quotes.

How to decode ' in c# [duplicate]

This question already has answers here:
Remove or Convert ' to (')
(3 answers)
Closed 7 years ago.
I found a similar question on how to decode ^#39; or simply ' in php, but I have been having trouble finding a way of decoding that value in c#. Thoughts? I have been trying the following in my code...
agenda.MeetingLocation = agenda.MeetingLocation.Replace("'", "''")
However, the value in my form field is John Doe's test. The value I see for agenda.MeetingLocation is:
John Doe's test
(the ^ is a &)
This should work if it's encoded like "& #39;" instead of "^#39;". Are you sure your input uses "^"?
System.Web.HttpUtility.HtmlDecode("John Doe's test.");

C# Equivalent to VB6 Chr(number) [duplicate]

This question already has answers here:
What's the equivalent of VB's Asc() and Chr() functions in C#?
(12 answers)
Closed 8 years ago.
I have this code:
Dim sCenter As String
sCenter = Chr(27) + Chr(97) + Chr(1)
And I'm trying to convert to a C# code. Online converters always fail to convert... :(
So, what is the C# equivalente of Chr(number)?
Maybe Char.ConvertFromUtf32(10);
Feel like taking risk to answer but how about?
string sCenter;
sCenter = "" + (char)27 + (char)97 + (char)1;
Thanks to James Curran's comment about char integral addition. As his suggested, I added meaningless "" with char to get string + char which uses .ToString() with String.Concat method at background.

Categories