format text

wschian

Registered User.
Local time
Yesterday, 16:21
Joined
Dec 12, 2013
Messages
19
hi!,
I want to format the text using format function. how i format the word apple to "apple" (With Quatation mark).
str = Format(Me.word, xxxx)

TQ
 
Last edited:
Hi:
There are a few ways to do this, and none of them use the Format() function.
  1. You can use the ascii code for the quote character, which is 34.
  2. You can enclose the double-quotes in single-quotes.
  3. You can use double double-quotes
Code:
[COLOR="Green"]'1. ascii code[/COLOR]
str = chr(34) & "apple" & chr(34)

[COLOR="Green"]'2. enclosed in single-quotes[/COLOR]
str = '"apple"'

[COLOR="Green"]'3. double double-quotes
'   when enclosed in double-quotes, a pair of double-quotes will yield 
'   a single double-quote character[/COLOR]
str = """apple"""
hth
 
hi!,
I want to format the text using format function. how i format the word apple to "apple" (With Quatation mark).
str = Format(Me.word, xxxx)

Normally we would just use one of the syntaxes Mark posted, but just to elucidate the nature of the Format function, here is the answer to your actual question about using Format():

Code:
str = Format("apple", "\""&&&&&&&\""")
The first double quote is the opening delimiter for the format string argument.

The next character, the backslash, is the literal escape for the subsequent character. Any character following a backslash will be included literally in the returned string.

However in this case the subsequent character we want is a double quote and that is a special case. A double quote must be escaped or it will be interpreted as closing the format string. Double quotes are self escaped so we enter "" to get one double quote just as Mark showed.

The ampersands are placeholders for the characters in the expression string argument. You need to include as many as the longest string anticipated or the double quote will end up in amongst the characters.

The literal double quote at the end is expressed similarly as the first by
Code:
\""
The final double quote is the closing delimiter for the format string.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom