ProperCase
我的.Net 代码中有一个函数,如下所示
Public Function ProperCase(ByVal strValue As String) As String
Dim outString As String = ""
Dim badWords As String = "and, at, do, de, du, USA, UK"
Dim splitter(1) As Char
splitter(0) = " "
Dim splitString As String() = strValue.Split(splitter)
For Each s As String In splitString
If badWords.Contains(s) Then
outString = outString & s & " "
Else
outString = outString & StrConv(s, VbStrConv.ProperCase) & " "
End If
Next
Return Trim(outString)
End Function
我需要对双桶名称进行适当的转换Taylor-Smith
,但它的出现就像Taylor-smith
因为拆分器是一个空格,所以我像这样修改了代码。
Public Function ProperCase(ByVal strValue As String) As String
Dim outString As String = ""
Dim badWords As String = "and, at, do, de, du, USA, UK"
Dim splitter(2) As Char
splitter(0) = " "
splitter(1) = "-"
Dim splitString As String() = strValue.Split(splitter)
For Each s As String In splitString
If badWords.Contains(s) Then
outString = outString & s
Else
outString = outString & StrConv(s, VbStrConv.ProperCase)
End If
Next
Return Trim(outString)
End Function
所以我在函数中添加了一个额外的拆分器,但现在它没有返回带有连字符的值。我& " "
从 outString 的末尾删除了,但我不确定我可以用什么替换它。
我尝试添加& splitter
,但即使分隔符是空格,它也总是返回连字符。
目前我正在用我修改过的代码得到这个
Mr TomHart
Mr JamieTaylorSmith
有了第一个版本的代码,我得到了这个
Mr Tom Hart
Mr Jamie Taylor-smith
我的预期输出是这样的......
Mr Tom Hart
Mr Jamie Taylor-Smith
有任何想法吗?