-1

ここでケーシング機能に問題があります。すべての接続詞を下位に変更するために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」である必要があります。出力によって「forward」に変更します。

例'メインイベントの場合と転送する場合'出力は'メインイベントの場合と転送する場合'

4

1 に答える 1

0

私はこのコードで試しました:

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

そして、正しい結果が得られます:



Kelvzy Sake のために、私はこの前払いをしています... FORWARD For-Ward...


わかった


編集:

例 「メイン イベントと転送先」の出力は、「メイン イベントと転送先」となります。

あなたのコードは大文字の F で Forward を出力します。これはまさにあなたが期待するものです。

ここに画像の説明を入力

編集2:

その理由は、^ で始まる/追加されないすべての単語が、次のコード行で ProperCase に変換されるためです。

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

ヒント: ProperCase に変換された単語は ^ で再固定/追加されないため、^ を "" に置き換える必要はありません。

于 2013-01-14T05:04:54.907 に答える