Is there a simple way of converting Word smart quotes to basic quotes

Robert Barnes 101 Reputation points
2024-08-14T02:51:16.92+00:00

The text for Error Help in my software (MANASYS Jazz) was prepared with Word, and so contains Word smart quotes, and probably other Word smart characters. When this text is displayed in a Windows Form, results can be confusing. For example,

User's image

The code below eliminates smart double-quotes, changing them back to the double-quote as I typed it. It has cleaned up "Jz" in the error text above.

Dim Text As String = ErrorElementT.Text
If InStr(Text, "‘") > 0 Then
    Text = Replace(Text, "‘", """")
    Text = Replace(Text, "’", """")
End If

I could extend this to cover single quotes, but there may be other characters that I'd miss. Is there a simple way of reverting all of the smart characters?

Thank you, Robert

Developer technologies VB
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 34,221 Reputation points Microsoft External Staff
    2024-08-14T06:41:44.6566667+00:00

    Hi @Robert Barnes ,

    You can first replace the smart brackets in the text loaded from Word by using the following method, and then make it appear in the text box.

    Function ReplaceSmartQuotes(text As String) As String
        Dim replacements As New Dictionary(Of String, String) From {
            {"“", """"},  ' Actual Left Double Quote
            {"”", """"},  ' Actual Right Double Quote
            {"‘", "'"},   ' Actual Left Single Quote
            {"’", "'"},   ' Actual Right Single Quote
            {"–", "-"},   ' Actual En Dash
            {"—", "-"},   ' Actual Em Dash
            {"…", "..."}, ' Actual Ellipsis
            {"•", "•"},   ' Bullet Point
            {"™", "™"},   ' Trademark Symbol
            {"'", "'"}    ' Apostrophe
        }
    
        For Each key As String In replacements.Keys
            text = text.Replace(key, replacements(key))
        Next
    
        Return text
    End Function
    
    
    

    Best Regards.

    Jiachen Li


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Robert Barnes 101 Reputation points
    2024-08-16T02:46:16.61+00:00

    Thank you everybody who helped. I found that Jiachen's routine wasn't directly useful, as the issue was that my error message table in a SQL database had already stored the error title and description with the smart quotes changed to the unwanted characters shown in the graphic of my original post, so looking for “ and other smart characters didn't help. However, it was very useful in giving me a list of the characters to look for. Using this list and my ErrorHelp program (that maintains the database and the error tables) I corrected the error at source, so the database no longer has the unwanted characters.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.