0

我想转

我沉迷于“花生”和“可可”

进入

我沉迷于“花生”和“可可”</p>

我该怎么做?有任何内置功能吗?

4

2 回答 2

2

当然没有内置函数。你到底如何让第一个单引号保持不变而第二个单引号改变。它背后必须有更多的逻辑才能给你想要的结果。我猜是一个解释英语语言结构的程序

当然,我在写了一些东西之后注意到了这个问题,根据你的需要编辑它,所以它不是为猫的尾巴而写的

 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
于 2011-07-25T11:41:12.327 回答
0

这将自动检测空格是在字符串之前还是之后,并采取适当的行动。

  Public Function SmartQuotes(ByVal someString As String) As String
        someString = " " + someString + " "
        Dim oldstring = someString
        someString = smarten(someString, "'"c, "‘"c, "’"c)
        someString = smarten(someString, """"c, Chr(147), Chr(148))
        If oldstring = someString Then
            Return Trim(someString)
        Else
            Return SmartQuotes(someString)
        End If
    End Function

    Public Function smarten(ByVal someString As String, ByVal original As Char, ByVal left As Char, ByVal right As Char) As String
        If someString.Contains(original) Then
            Dim index = someString.IndexOf(original)
            If leftQuoteorRightquote(someString, index) Then
                someString = someString.Remove(index, 1).Insert(index, left)
            Else
                someString = someString.Remove(index, 1).Insert(index, right)
            End If
        End If
        Return someString
    End Function
    Public Function leftQuoteorRightquote(ByVal somestring As String, ByVal index As Integer) As Boolean
        If somestring.Substring(index - 1, 1) = " " And somestring.Substring(index + 1, 1) <> " " Then
            Return True
        Else
            Return False
        End If
    End Function
于 2011-07-26T03:53:45.780 回答