Escape sequence in VB Strings (and Characters) 
Author Message
 Escape sequence in VB Strings (and Characters)

The new character literal is useful, but IMHO we need some way to define
general non-printable characters, such as escape sequences.

I know ControlChars provides some and ChrW can give us the rest and there are
more liberal definitions of what is a constant expression, but something like
"\0169"c looks better (source is more portable between fonts!) to me than
"?"c, even though the latter works -- and looks good in *my* font.

Now what should we use as an escape sequence in VB?

Note that an escape sequence looks like the character it is representing to
the compiler (that is, wherever escape sequences are recognised -- character
or string literals). So printf("\t") in C, etc, passes a string containing
just a tab character, and the printf code does not have to decode "backslash
t".

In VB we've escaped the double quote by duplicating it, which means we don't
have a general escape sequence available to extend to extra characters, but it
also means we don't *have* to use backslash.

A suggested syntax: C-style escape sequences between the 'duplicate quote':

  "Copyright: "\0169"2002 Mark Hurd"\t"All rights reserved." _
  " Continuation like in C."

Explaining that fully:
 a string literal is currently: "([^"]|"")*"
 I suggest: "([^"]|"[whitespace|\Coptions]")*"
   where whitespace means concatenation
   Coptions means t,r,n,o77,xe2,0169,etc, but not " and '
   and, of course, nothing means "

Now I like this idea, but it does mean & becomes optional between string
literals! Haven't thought it through much more than this and I have no idea if
the parser will get stuck on seeing this as a bad attempt at integer division.
Though if it does, it should use the same 'feature' that means "..."& is seen
as an attempt to make a long string (and has for many VB versions).

And because characters can't currently contain more than one character (except
for double quote), the "outer" set of quotes are optional:

"\0169"c is the same as ""\0169""c is the same as the first character of
""\0169""
"\0"c is the same as ""\0""c is the same as ControlChars.NullChar (which
should be Nul !)
"\t"c is the same as ""\t""c  is the same as ControlChars.Tab

Logical extension: ""c is the same as """"c and ControlChars.Quote ?!!

Regards,
Mark Hurd, B.Sc.(Ma.) (Hons.)



Mon, 21 Jun 2004 09:31:31 GMT  
 Escape sequence in VB Strings (and Characters)
Since original Visual Basic is designed for development of Windwos
Application, not a "command line" one. IN VB, a string will often be
consider as a object nad use different way to format output. So its syntax
doesn't has escape sequence. In VB 5.0 or 6.0, we will use Chr() or ChrW()
to get the non-printable char. It is a difference between C and Basic
synatx.

Luke



Sat, 26 Jun 2004 15:27:13 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. writing double quote with escape sequence in string?

2. escape Javascript equivalant in VBA for URL Escape Sequences

3. Using HP Printer Escape Sequences (aka Printer Passthrough Codes) in VB.Net

4. Printing Escape Sequences through VB

5. Printing Escape Sequences through VB (is there an API)

6. Escaping Characters in VB

7. How to Convert Escape Characters from C# to VB.NET

8. escape characters in VB?

9. escaping characters in VB?

10. printing escape sequences for direct printer control to print micr on checks

11. Printer Escape Sequences

12. Open lpt1 for output escape-sequences

 

 
Powered by phpBB® Forum Software