" and '
" and '
" and '
" and '
" and '
" and ' " and ' " and ' " and ' " and ' " and ' " and ' " and '
" and ' " and '
" and '
Go Back  Xtreme Visual Basic Talk > > > " and '


Reply
 
Thread Tools Display Modes
  #1  
Old 05-25-2008, 03:55 PM
3dkingpin 3dkingpin is offline
Junior Contributor
 
Join Date: Feb 2008
Posts: 256
Default " and '


ok vb uses ' to indicate a comment. Im use to using // for inserting comments

now this creates a problem for me in that how do i check if a string contains inverted commas?

for example say i read the following text from a text file into a string 'testfunction("hello")'

now how would i check for the occurences of inverted commas in the string.

if i did
PHP Code:
valueInStr(1_string" " ", CompareMethod.Binary) 
it would not work
and neither would
PHP Code:
valueInStr(1_string' " 'CompareMethod.Binary
Reply With Quote
  #2  
Old 05-25-2008, 04:18 PM
MKoslof's Avatar
MKoslof" and ' MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

The Substring, IndexOf, LastIndexOf, IndexOfAny, etc would suffice. If you want the inverted comma or ' you want to search for the actual apostrophe. " ' ".ToCharArray() for example. Look at the native methods within the .Net string class.
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #3  
Old 05-26-2008, 09:34 AM
AtmaWeapon's Avatar
AtmaWeapon" and ' AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

Nitpicker note:
Inverted comma (both left and right) are different characters than apostrophe; they can be represented in html by ’ ‘ or the entities #8216 and #8217; it's a typographical shame that it's not easy to produce them with a keyboard. However, VB .NET does not interpret either of these characters as a comment character.

This is a string that contains an apostrophe:
"'"

The double quote character is the string literal terminal character, so if it appears in a string you have to escape it. A double quote character is escaped by placing two quotes in place of each quote; this is a string that contains a double quote character:
""""

VB character literals end with the c suffix; the following is an apostrophe character and a double quote character:
"'"c """"c

It's rare that you need to distinguish between the two, but it's maddening when you do and you don't know this.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #4  
Old 05-27-2008, 05:03 AM
3dkingpin 3dkingpin is offline
Junior Contributor
 
Join Date: Feb 2008
Posts: 256
Default

so wud dis werk:

value= InStr(1, _string, ' " c, CompareMethod.Binary)

value= InStr(1, _string, " ' c, CompareMethod.Binary)
Reply With Quote
  #5  
Old 05-27-2008, 08:05 AM
AtmaWeapon's Avatar
AtmaWeapon" and ' AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

No, you didn't quite catch it.

Every token in the language is defined by a grammar rule. A simplified way to express the grammar for a character literal could be as follows:
Code:
<charLiteralStart>(<character>|<escapedCharacter>){1}<charLiteralEnd>c
charLiteralStart is the " character. <charLiteralEnd is the " character. This means that to have a character literal, you at minimum need two double-quotes and the "c" character. It would look like this:
Code:
""c
.

<character> is easy to figure out; it is any character other than the double quote character (") as far as I know. <escapedCharacter> stands for any character that needs to be escaped; the only one I know of is the double quote character ("), and it is escaped by placing two double quotes for every single double quote desired.

Let's walk through the grammar for producing the ' character from a literal. We want it to look like this:
<charLiteralStart>'<charLiteralEnd>c

<charLiteralStart> and <charLiteralEnd> are always a single double quote, so now we have:
"'"c

Since ' is not an escaped character, we leave it as-is.

Let's walk through the method for making a double-quote character:
<charLiteralStart>"<charLiteralEnd>c

<charLiteralStart> and <charLiteralEnd> are always a single double quote, so now we have:
"""c

Ah, but the double-quote character needs to be escaped. This means that we need to replace the double quote with two double quotes:
""""c

Let's break it down into the pieces:
  • <charLiteralStart>: "
  • <escapedCharacter>: ""
  • <charLiteralEnd>: "
  • c

All of this is very similar for strings; the grammar rule allows for multiple characters or escaped characters and also does not require the "c". So, if I wanted a string that looked like this HTML tag:
<span class="productName">test text</span>

I would simply put quotes around it, then escape each quote in the string:
"<span class=""productName"">test text</span>"
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
&quot; and '
&quot; and '
&quot; and ' &quot; and '
&quot; and '
&quot; and '
&quot; and ' &quot; and ' &quot; and ' &quot; and ' &quot; and ' &quot; and ' &quot; and '
&quot; and '
&quot; and '
 
&quot; and '
&quot; and '
 
-->