String Declaration

vkid12

New member
Joined
Mar 24, 2015
Messages
2
Programming Experience
Beginner
I want to declare a string.


C#:
Public String SimplingString = "http://www.simpleurl.com/help:{}"""""}[]:""
I'm having issues with the symbols in the URL, any way to declare a string as an URL without those conflicts?
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,144
Location
Sydney, Australia
Programming Experience
10+
Is there an function to automatically do that for the URL ?
No. It's code that you write that is then interpreted by the compiler. There are basically two ways to write string literals: with escape character support or without.
// string literals with escape character support:
var s1 = "C:\\MyFolder\\MyFile.ext";
var s2 = "He said \"Hello\" to me.";

// verbatim string literals:
var s3 = @"C:\MyFolder\MyFile.ext";
var s4 = @"He said ""Hello"" to me.";
Verbatim string literals behave pretty much exactly the same way as VB String literals. You don't have to escape the usual escape character, which makes them good for file paths, and you can't use the usual escape character to escape anything else either, which means that double quotes get escaped with another double quote instead.
 
Top Bottom