String Literals

A string literal constant is a hard coded string value.
There are two types of string literals in C#.
You have the regular string literal which is enclosed in speech marks.
You also have the verbatim literal which is prefixed with an ampersand character.


Regular String Literals

string myString; 
myString = "C:/temp"
System.Diagnostics.Trace.Write(myString); '= "C:/temp"

myString = "C://temp"
System.Diagnostics.Trace.Write(myString); '= "C://temp"

Some characters cannot be included directly into a string, for example a double quotation mark.
Instead of using just these characters you will have to prefix them with an escape sequence.

myString = "C:\\temp" 
System.Diagnostics.Trace.Write(myString); '= "C:\temp"

myString = "C:\"temp"
System.Diagnostics.Trace.Write(myString); '= "C:"temp"


Hard code a string literal

If you want to hard code a string literal to get the length

"Details (" & sMyId & ")" 
= SubString(Len("Details"))

Returning the Length of a Constant

String.Copy("some text").Length 

Common Escape Sequences

\'single quote - needed for character literals
\"double quote - used to print a double quote character, needed for string literals
\\backslash - used to print a backslash character
\nnewline - position the cursor at the beginning of the next line
\thorizontal tab - move the cursor to the next tab stop
\rcarriage return - positions the cursor at the beginning of the current line
\vvertical quote
\aAlert
\bBackspace
\fform feed

© 2023 Better Solutions Limited. All Rights Reserved. © 2023 Better Solutions Limited TopPrevNext