【发布时间】:2019-09-01 14:05:42
【问题描述】:
我想创建转换的 ProperCase 文本函数:
O'Shanesy, Ben'S and frank'S tires
到:
O'Shanesy, Ben's and Frank's tires
如何让 strReturn.Replace("'S", "'s") 仅在 s 后没有字符时才起作用?
Public Function fProperCase(ByVal strTextIn As String, Optional ByVal bolIncludingAnd As Boolean = True) As String
Dim strReturn As String = strTextIn.Trim
strReturn = StrConv(strTextIn, VbStrConv.ProperCase)
If bolIncludingAnd = False Then
strReturn = strReturn.Replace("And", "and")
End If
'Change all 'S to 's unless there is
'another letter straight after
strReturn.Replace("'S", "'s")
Return strReturn
End Function
【问题讨论】:
-
应该这样做 -
strReturn.Replace("'S ", "'s ") -
AmarDuplantier 非常好,但如果短语是 O'Shanesy、Ben'S 和 frank'S 会怎样。更新:没问题我只能检查最后两个字符。谢谢。
-
不幸的是,它不适用于标点符号,例如。如果是“O'Shanesy、Ben'S 和 frank's”,它仍然是“Ben'S”