AlastairG AlastairG - 1 year ago 295
C# Question

Unquote string in C#

Please forgive my laziness. I could figure this out by reading up, I know, but I thought I'd give one of you C# geniuses the chance to win some rep.

I have a data file in INI file like format that needs to be read by both some C code and some C# code. The C code expects string values to be surrounded in quotes. The C# equivalent code is using some underlying class or something I have no control over, but basically it includes the quotes as part of the output string. I.e. data file contents of

MY_VAL="Hello World!"

gives me

"Hello World!"

in my C# string, when I really need it to contain

Hello World!

How do I conditionally (on having first and last character being a ") remove the quotes and get the string contents that I want.

Thankyou very much.

Answer Source

On your string use Trim with the " as char:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download