Tuesday, October 18, 2011

How to pass " within a string variable in C#?

 Some times we need to assign string like "<table id="tableStudent"> " or "Hello "Bishnu!" but we know that we cannot set " within a string because string are know as within a " (quotation)  mark. so for assign string like above we have to these to literals
1. Regular string literals
2. Verbatim string literals
 Here I describe both with example
Regular String Literals:
For this we must embed escape characters provided by C#

string strStringToFind = "<table id=\"tableStudent\"";
Output: <table id="tableStudent";

Verbatim String Literals:


string strString= @"Hello ""Bishnu!""";

Output: Hello "Bishnu!"
Hope this help you..