Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using the literal '@' with a string variable

Tags:

string

c#

I have a helper class pulling a string from an XML file. That string is a file path (so it has backslashes in it). I need to use that string as it is... How can I use it like I would with the literal command?

Instead of this:

string filePath = @"C:\somepath\file.txt";

I want to do this:

string filePath = @helper.getFilePath(); //getFilePath returns a string

This isn't how I am actually using it; it is just to make what I mean a little clearer. Is there some sort of .ToLiteral() or something?

like image 782
naspinski Avatar asked Sep 23 '08 12:09

naspinski


People also ask

How do you do a string literal in Python?

A string literal can be created by writing a text(a group of Characters ) surrounded by the single(”), double(“”), or triple quotes. By using triple quotes we can write multi-line strings or display in the desired way.

How do you make a string literal?

A "string literal" is a sequence of characters from the source character set enclosed in double quotation marks (" "). String literals are used to represent a sequence of characters which, taken together, form a null-terminated string. You must always prefix wide-string literals with the letter L.

What is string literal in JavaScript?

Template literals are literals delimited with backtick ( ` ) characters, allowing for multi-line strings, string interpolation with embedded expressions, and special constructs called tagged templates.


1 Answers

I don't think you have to worry about it if you already have the value. The @ operator is for when you're specifying the string (like in your first code snippet).

What are you attempting to do with the path string that isn't working?

like image 157
brock.holum Avatar answered Sep 30 '22 20:09

brock.holum