It would be very helpful If you could explain me about 'speech mark', I'm not that much professional in this field.
COmputer code is written in text. Some symbols have special meanings, like in VB the speech mark " (also called quotes, or doubleqoutes) is used to define where a string (sentence of text) starts and stoips.
Dim str as String = "Hello World"
Naturally, it thus causes difficulty when you want to use that same symbol, in the text itself. In this case, you want to send the following to the database:
SELECT "(" + field + ")" FROM table
If you use that straight in, it will confused vb, because VB will think youre trying to start and stop the string, and you end up with some illegal syntax:
Dim str as String = "
SELECT "(" + field + ")" FROM table"
I underlined the bit that you want VB to see as a string, the problem is that as soon as VB hits the first " after SELECT< it will think youre trying to stop the string, then later youre trying to start it, then stop it.. Very confusing for a computer, im sure you understand.
Instead, we must use what is called and escaped character - This is a way of writing a symbol so that VB knows we want to use the symbol itself (speech mark/doublequote) and not the special meaning (start/stop a string).
In VB the escaped form of a speech mark is to double it up:
Dim str as String = "
SELECT ""("" + field + "")"" FROM table"
VB knows that when you write "" in a string, you arent wishing to stop and start it, you are wishing to literally have one " in the string.
Other examples you might find as you program are:
{ in a format string
You can specify a format string and have VB put things into the placeholders:
Dim str as String = String.Format("The price of {0} is ${1:0.00} today, {2:yyyy MM dd}", "apples", 9.9941, DateTime.Now)
str will contain
The price of apples is $9.99 today, 2007 03 31.
The placeholders are noted by {0}, {1:0.00} and {2:yyyy MM dd}
Note they run in order, {0, {1, {2
The bit after the colon is the formatting of that item, i.e. the number 9.9941 being formatted into 0.00 form, or the date being formatted into yyyy MM dd
What hapens though, if we want to literally write a girly bracket { followed by a 0 in a string? Same problem as before:
Dim str as String = String.Format("I want a string that literally has { followed by 0 followed by }, i.e. {0}")
This code will break because VB will think we are trying for a placeholder, but we arent. Again, this time we have to escape the { so that VB doesnt think we are trying to put placeholders in:
Dim str as String = String.Format("I want a string that literally has {{ followed by 0 followed by }}, i.e. {{0}}")
Other times, a backslash is used for escaping.. In most other languages than VB it is common place. It occurs in places in vb where vb has borrowed from those languages, such as Perl-style Regular Expressions.
RegExes are a language of their own, and very good at finding patterns in text.
RegularExpressions are all about special characters, and one for example, is the period/fullstop/dot:
.
To regex, this means "match any single character" a bit like the ? meant in old DOS
So, Dot will find anything.. How do you search for a Dot? You want to know where the first period is in a sentence. Searching using:
.
Gives you index 0, i.e. it finds the first character of the sentence and succeeds. If however, we search using:
\.
Then the first period/fullstop/dot is found.
Hopefully you now have a better understanding of the way programming languages have to work, if we want to write in the same characters that we do for everyday lives, but have those characters mean something special to the computer, then we also need to have a way of telling the computer when we dont want them as special.. just as normal, everyday characters
The following webpage might interest you:
http://blogs.msdn.com/brada/archive/2004/01/14/58851.aspx