适当的信件套管

时间:2013-01-14 04:00:46

标签: vb.net casing

我的套管功能有问题。 我使用replace来将所有连接更改为更低但仍然有错误>

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' 通过我的输出将其更改为“前进”

示例'对于主要事件和我们转发',输出应为'主要事件和我们转发'

1 个答案:

答案 0 :(得分:0)

我尝试使用此代码:

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

我得到了正确的结果:

  
     
     

对于Kelvzy Sake我正在支付这个前进... FORWARD For-Ward ...

     
     

好的

     

修改:

  

示例'对于主要事件和我们要转发'输出应该   成为'主要活动和我们前进'

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

enter image description here

编辑2:

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

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

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