vb.netbuilt-insmart-quotes

Is there a Built in VB.net function to turn quotes into smartquotes


I want to turn

I'm addicted to 'peanuts' and "cocoa"

into

I’m addicted to ‘peanuts’ and “cocoa”

How would I do that? Any built in function for that?


Solution

  • Of course there is no builtin function. How on earth would you leave the 1st single quote unchanged and the 2nd changed. There has to be more logic behind it to give you the result you want. A program that interprets the english language construct, I guess

    Of cource I noted the problem AFTER writing something, edit it for your needs, so it's not written for the cat's tail

     Function trSmart(s As String) As String
        Dim inSngl As Boolean = False
        Dim inDbl As Boolean = False
        For i = 1 To s.Length()
            If s(i - 1) = "'"c Then
                If inSngl Then
                    s = s.Substring(0, i - 1) & Chr(146) & s.Substring(i)
                    inSngl = False
                Else
                    s = s.Substring(0, i - 1) & Chr(145) & s.Substring(i)
                    inSngl = True
                End If
            ElseIf s(i - 1) = """"c Then
                If inDbl Then
                    s = s.Substring(0, i - 1) & Chr(147) & s.Substring(i)
                    inDbl = False
                Else
                    s = s.Substring(0, i - 1) & Chr(148) & s.Substring(i)
                    inDbl = True
                End If
            End If
        Next
        Return s
    End Function