-1

I have a Problem here in my casing function. I used replace to change the all conjunction into a lower but still i have an error>

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

error sample: 'For' should be 'for' but the word 'Forward' must be 'Forward' by my output change it into 'forward'

Example 'For the main event and for us to forward' the output should be 'For the Main Event and for us to Forward'

kelvzy
  • 913
  • 2
  • 12
  • 19

1 Answers1

0

I tried with this code:

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

And I get the correct result:



For Kelvzy Sake I Am PAYING This Forward... FORWARD For-Ward...


OK


Edit:

Example 'For the main event and for us to forward' the output should be 'For the Main Event and for us to Forward'

Your code outputs Forward with a capital F, which exactly what you expect.

enter image description here

Edit 2:

The reason is because all words that are not prefixed/appended with ^ are converted to ProperCase with this line of code:

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

Tip: there is no need to replace ^ with "" because words converted to ProperCase are not refixed/appended with ^.

Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
  • yes but still wrong, all words must be in a Proper casing except for words with '^' but if the word 'for' is in between the sentence it must be in a lowercase, – kelvzy Jan 14 '13 at 06:27
  • " For " is what you're looking for in your replace but the string only contains "For " and " For-Ward" – allen.mn Jan 14 '13 at 15:10
  • "For the main event and for us to forward" should be the output – kelvzy Jan 15 '13 at 04:03
  • Uh huh. If you read the last two lines of your question you can see its contrary to what you want and it totally mislead me. See my second edit for solution. Good luck! – Jeremy Thompson Jan 15 '13 at 04:34