我有一個ProperCase
功能在我的.Net代碼像這樣與hypens Propercase功能
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
我需要propercase像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
任何想法?
樣品輸入,輸出和預期產出將會有所幫助。我沒有看到你遇到的問題。 – Oded 2012-04-19 14:47:54
@Oded我和預期產出更新 - 感謝 – 2012-04-19 15:01:46