Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Apostrophe

Status
Not open for further replies.

kimtp

Programmer
Jun 15, 2002
310
US
Ran into something that baffles me. I have a rtf textbox and am trying to allow for the use of the apostrophe ('). Did a svar = replace(svar," ' ",chr(180)). That works for a last name such as O'Rourke. However, when using the same replace method for a contraction (we're) the letters "b4" were inserted each time - (we'b4re).

Next I changed the replacement to chr(146) and it seems to have solved the problem.

Any one have any explanation why one works and the other does not? Also is chr(39) the apostrophe being replaced?

Thanx.

Kim
 
Could you cut and paste the actual statement you use - I can't duplicate the problem

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
chr(39) is the single qoute mark.

I tried exactly what you did and it worked fine, but I thought Chr(96) was an apastrophe (on the key with the tilde).

I just ran into this problem with a database application where, if the user entered a single quote mark (Chr(39)), the program threw an error. Now, before sending the data to the db, I do a Replace(str1, "'", "`"). Works fine now!

tbuch
 
Here is the statement that brings the trouble:

Public Sub LetterUpdate(ByRef sLetterName As String, sMemo As String)
sMemo = Replace(sMemo, "'", Chr(180))
sLetterName = Replace(sLetterName, "'", Chr(180))
sSql = "UPDATE Letter SET fldName = '" & sLetterName & "'," & _
" fldLetter = '" & sMemo & "' WHERE fldName = '" & sLetterName & "'"
rsMemo_Open sSql, cData

This is the result of using chr(180. Note the b4 in the contraction on line 5):

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Arial;}}
\viewkind4\uc1\pard\fs24 Howdy
\par
\par We\´b4ve done it
\par }

Changing the chr(180) to chr(146) cures it for this problem.

tbuch - The apostrophe (`) sharing the tilde key (~) is chr(180). You have done the same thing as Replace(sMemo, "'", Chr(180))

Any ideas as to why?

thanx
Kim
 
The answer appears OK in the actual RichTextBox control - if you look in the richtext source (as you've done) you'll find that all characters above 127 are replaced by their escape sequence equivalent. If they've got a name like rquote, then it's used. Otrherwise it uses the Hex value of the character. So chr(146) translates to \rquote (right quote) and chr(180) translates to \'b4 (b4 Hex = 180 Decimal)



________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
\'<nn> is what is known as an 'escaped expression', where <nn> is the hex value of the character being escaped. Note that hex B4 = Dec 180.

(It is just an unfortunate coincidence that the character sequence that flags an escaped expression happens to contain the character you were trying to insert)

However, by including your code it now becomes evident why you are trying to replace the apostrophe with an alternative - because you want to save the text into a database and have been getting errors when you have an apostrophe in the text you submit. Can you confirm this is the case?
 
Many thanx for the help. strongm - yes I am storing this info in a database. thanx to you and johnwm for enlightening me concerning the hex stuff.

vbacock - I am not familiar with stored procedures. Can you point me in the direction?

thanx.

Kim
 
kimpeterson,

The apostrophe on the tilde key IS Chr(96) :-b

:)

tbuch
 
tbuch,
That may depend on which keyboard mapping you're using! Different keyboards (and different International settings) will produce different characters from the same keys.

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Good point johnwm. I sometimes forget about int'l settings.
 
vbcock - using Access.

tbuch = you're right. On this keyboard 180 has a forward look whereas 96 has a backward look (`).

Thanx for the help.

Kim
 
The reason I asked the question was because you may not actually need to replace the apostrophe with an alternate character at all. We've discussed this a number of times, and here are some threads that may shed some light on the subject:

thread222-549287
thread222-485947
thread222-420046
 
Another approach would be to use the textbox's keypress event and, if a single quote is entered, changed it then to an apostrophe.
 
strongm - thanx for the jumps (threads). Ended up using the replace(var,&quot; ' &quot;,&quot; ' ' &quot;) and it seems to be working for all imaginable variations (an impossiblity?).

thanx to all for the help.

Kim
 

You could also use a Command object and a Parameter object.
You don't need a stored proceedure for this.
Then you will not have to replace anything. Works with JET MDB as well.
 
Pah! That's already covered (by your good self) in the first of the three links I gave.
 

This must have been one of those electronic echos produced somehow by intelligent software (it was even re-worded)!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top