-1

我的套管功能有问题。我使用替换将所有连词更改为较低的但我仍然有一个错误>

Private Function UpCsing(ByVal sValue As String) As String
    Dim toConvert As String() = sValue.Split(" ")
    Dim lst As New List(Of String)

    For i As Integer = 0 To toConvert.Length - 1
        Dim converted As String = ""
        If toConvert(i).Contains("^") Then
            converted = toConvert(i).ToUpper.Replace("^", "")
        Else
            converted = StrConv(toConvert(i), VbStrConv.ProperCase).Replace("^", "")
        End If
        lst.Add(converted)

    Next
    Dim ret As String = ""
    For i As Integer = 0 To lst.Count - 1
        If i = 0 Then
            ret = lst(0)
        Else
            ret += " " + lst(i)
        End If
    Next
    Return ret.Replace(" For ", " for ").Replace(" In ", " in ").Replace(" Of ", " of ").Replace(" And ", " and ").Replace(" And/Or ", " and/or ").Replace(" By ", " by ") _
.Replace(" By ", " by").Replace(" 2Nd ", " 2nd ").Replace(" 3Rd ", " 3rd ").Replace(" At ", " at ").Replace("And/Or ", "and/or ").Replace("1St", "1st").Replace("2Nd", "2nd").Replace("3Rd", "3rd") _
.Replace("At ", "at ").Replace(" At", " at").Replace(" Of", " of").Replace(" & ", " and ").Replace("Poc", "POC").Replace(" As ", " as ") _
.Replace("C/O", "c/o").Replace("$ ", "$").Replace(" And/Or ", " and/or ")


End Function

错误示例:'For' 应该是 'for' 但我的输出中的单词 'Forward' 必须是 'Forward' 将其更改为 'forward'

示例 'For the main event and for us to forward' 输出应该是 'For the Main Event and for us to Forward'

4

1 回答 1

0

我试过这段代码:

MessageBox.Show(UpCsing("for kelvzy sake I am paying^ this forward... forward^ for-ward..."))

我得到了正确的结果:



为了 Kelvzy 的缘故,我正在为这个前锋付出代价...... FORWARD 前锋......


好的


编辑:

示例 'For the main event and for us to forward' 输出应该是 'For the Main Event and for us to Forward'

您的代码以大写 F 输出 Forward,这正是您所期望的。

在此处输入图像描述

编辑2:

原因是因为所有没有前缀/附加 ^ 的单词都使用这行代码转换为 ProperCase:

converted = StrConv(toConvert(i), VbStrConv.ProperCase).Replace("^", "")

提示:无需将 ^ 替换为“”,因为转换为 ProperCase 的单词不会重新固定/附加 ^。

于 2013-01-14T05:04:54.907 回答