Apostrophe Replacement with InStr

I’m writing an app to find and replace parts of text in the rows of a listbox, i’ve got most of it working but cannot get InStr to find apostrophes in the string value to replace it

Here is the code

stocheck = listbox1.cell(1,0)
contents = InStr(stocheck, “’”)

are they the ASCII apostrophe ?
or “smart quotes” which are entirely different characters

If they are real apostrophes, it is different from single quote.

It’s a single quote that I’m searching for in the string, so could be I’m, Don’t etc but try these and it still does not find them.

On Mac if you have curly quotes on, chances are it is not a single quote anymore. Same thing if the text is coming from Word.

if that instr is not finding them then its not the ASCII single quote character
its more likely the right single quote or something else

and you can find those with something like

stocheck = listbox1.cell(1,0)
contents = InStr(stocheck, &u2019)

and there are a pile more that are possible. see http://www.fileformat.info/info/unicode/block/general_punctuation/images.htm

Tried &u2019 and still does not find it in the string. The listbox gets it’s contents from the filenames in a folder

So find out what it is. Locate the Don’t and examine the 4th character.

Or copy and paste a sample string here so we can have a look.

The “true” Apostrophe is &U0027. Perhaps in addition to the more common &U2019, you could also check for &U0027?

That is what the code he first posted should be locating

True. I am curious however to find out whether InStr(string, “’”) is looking for &U2019 or &U0027, or even just ASCII character 39.

&U0027 IS, by definition, ASCII character 39

More on this.
I am Searching a TextArea for single quotes and double quotes and it is not finding them in
my routine.

note: CmpPattern and CmpReplace are regular expression routines that have proven to work in oodles of routines and multi apps
ItemDescription is a textarea

Dim DQ As String = Chr(34)  // double quote
Dim SQ As String = Chr(39) // single quote
if CmpPattern(ItemDescription.text, "[" + DQ + SQ + "]+") = True Then
  ItemDescription.Text = CmpReplace(ItemDescription.Text, DQ, """)
  ItemDescription.Text = CmpReplace(ItemDescription.Text, SQ, "'")
end if

note: Instr also fails the comparrisio

if Instr(ItemDecription.Text, DQ) > 0 then
end if

however this does work where ItemText is a Text Field.

if CmpPattern(ItemTitle.text, "[" + DQ + SQ + "]+") = True then
  ItemTitle.Text = CmpReplace(ItemTitle.Text, DQ, """)
  ItemTitle.Text = CmpReplace(ItemTitle.Text, SQ, "'")
End if

i am perplexed as to why the comparrision works in one case with a Text Field but fails with a TextArea

Please advise…

they’re not “smart quotes” or “curly quotes” are they ?
those are different code points entirely


why not just use REPLACEALL??

 ItemTitle.Text = replaceAll( ItemTitle.Text,chrb(34),""")
 ItemTitle.Text = replaceAll( ItemTitle.Text,chrb(39),"'")

assuming they are NOT “smart” as Norman mentioned

		// Turn OFF Smart Quotes
		#If TargetCocoa Then
				Dim value As Boolean = False
				Declare Function NSClassFromString Lib "Cocoa" (aClassName As CFStringRef) As Ptr
				Declare Function documentView Lib "Cocoa" selector "documentView" (obj_id As Integer) As Ptr
				Declare Sub setAutomaticQuoteSubstitutionEnabled Lib "Cocoa" selector "setAutomaticQuoteSubstitutionEnabled:" (id As ptr, value As Boolean)
				Declare Sub setAutomaticDashSubstitutionEnabled Lib "Cocoa" selector "setAutomaticDashSubstitutionEnabled:" (id As ptr, value As Boolean)
				Declare Sub setAutomaticTextReplacementEnabled Lib "Cocoa" selector "setAutomaticTextReplacementEnabled:" (id As ptr, value As Boolean)
				Dim myTextArea As ptr = documentView(Self.Handle)
				setAutomaticQuoteSubstitutionEnabled(myTextArea, value)
				setAutomaticDashSubstitutionEnabled(myTextArea, value)
				setAutomaticTextReplacementEnabled(myTextArea, value)  
				Dim xStart As Integer=Me.SelStart
				Dim xLen As Integer=Me.SelLength
				Me.Text = ReplaceAll(Me.Text,&u201C,dblQUOTE)
				Me.Text = ReplaceAll(Me.Text,&u201D,dblQUOTE)
				// single quotes
				Me.Text = ReplaceAll(Me.Text,&u2018,sngQUOTE)
				Me.Text = ReplaceAll(Me.Text,&u2019,sngQUOTE)
				// lower right quotes
				Me.Text = ReplaceAll(Me.Text,&u201A,sngQUOTE) // ‚
				Me.Text = ReplaceAll(Me.Text,&u201E,dblQUOTE) // „

my eyes are not what they used to be but i believe the single quotes are just straight not curley, just neutral.
and double quotes are just double quotes.

Note: at one time my routines worked, now they do not work.

i will try different strategies

They can be a bugger to spot visually
Sometime I just zoom the screen in on my Mac to be sure
And then poke at the binary in the string to see for sure


I am sure the ReplaceAll will work but the problem is the “if” testing to see if the quote are there fails with my Cmp Routine and Instr


your right i zoomed in and they are curley, gee , didn’t see that before.