"Oenone" <no***@nowhere.com> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
GysAnn wrote: I'm looking for a function for converting the input to a regular text.
Example: when the input is "aBCdefgHI jkLM ooPP" the return value
of the function should be "Abcdefghi Jklm Oopp"
Dim oldText As String
Dim newText As String
'Get the original text
oldText = "aBCdefgHI jkLM ooPP"
'Convert to Proper Case
newText = StrConv(oldText, VbStrConv.ProperCase)
'Remove any double-spaces
Do While InStr(newText, " ") > 0
newtext = replace(newtext," "," ")
Loop
'All done
MsgBox(newText)
StrConv with ProperCase enum will only uppercase the first letter in each
word in the phrase..
so...
Sub Main()
Dim text As String = "aBCdefgHI jkLM ooPP"
Console.WriteLine("Before ReCasing : " & text)
text = ReCaseString(text)
Console.WriteLine("After ReCasing : " & text)
text = RemoveDblSpaces(text)
Console.WriteLine("After Removing DblSpaces: " & text)
End Sub
Private Function ReCaseString(ByVal Text As String) As String
Dim chars As Char() = Text.ToCharArray()
Text = String.Empty
For Each ch As Char In chars
If Char.IsLower(ch)
ch = Char.ToUpper(ch)
Else
ch = Char.ToLower(ch)
End If
Text &= ch
Next
Return Text
End Function
Private Function RemoveDblSpaces(ByVal Text As String) As String
While Text.IndexOf(Space(2)) > 0
Text = Text.Replace(Space(2), Space(1))
End While
Return Text
End Function