Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chr(34) equivalent

Tags:

c#

vb.net

I am converting VB.NET code to c# and I am stopped when I reached the following code snippet. I need someone's help to convert Chr(34). Please help me to convert it to c#.

VB.NET Code

Dim inputString As String
inputString = "Some text ..."
inputString = Replace(inputString, Chr(34), "")**

My c# conversion is

string inputString = "Some text ...";
inputString = inputString.Replace(NEED HELP HERE, "");**
like image 632
Neetisa Avatar asked Sep 19 '17 11:09

Neetisa


2 Answers

You can cast an integer to a char, so an "automatic" translation would be:

inputString = inputString.Replace(, ((char) 34).ToString(), "")

That being said, the characters that maps to 34 (according to ASCII) is ", so you can simply construct a string with the double quote char:

inputString = inputString.Replace(, "\"", "")

This will also improve readability, since it is now clear what you are doing in that part: you remove double quotation characters.

like image 153
Willem Van Onsem Avatar answered Nov 16 '22 19:11

Willem Van Onsem


Converted code below:

string inputString = null;
inputString = "Some text ...";
inputString = Strings.Replace(inputString, Strings.Chr(34), "");

I would recommend to use any converter if you are not dealing any confidential details. This will save sometime.

In fact, I used this tool to convert your code.

like image 5
Karthick Raju Avatar answered Nov 16 '22 20:11

Karthick Raju