String.ToUpper

  • Thread starter Thread starter Kerri
  • Start date Start date
K

Kerri

Hi,

I have a string 'hello world'

I can UCase my string using String.ToUpper

Is there anyway to just UCase the first letter ofe ach
word?

Thanks,
Keeri.
 
Kerri said:
I have a string 'hello world'
I can UCase my string using String.ToUpper

Is there anyway to just UCase the first letter ofe ach
word?

Use ----> VbStrConv.ProperCase

Dim strName As String = txbModUser.Text
strName = StrConv(strName, VbStrConv.ProperCase)
txbModUser.Text = strName

Regards,

Bruce
 
Hmmm....the ToTitleCase method of the TextInfo object works like someone
else suggested here.

Or you could use regular expressions with a delegate function as in the code
below. I think the TotitleCase method would be much faster for iterative
operations...maybe :-)

Ibrahim Malluf


Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

Dim MyReg As New System.Text.RegularExpressions.Regex("\b\w*\b",
System.Text.RegularExpressions.RegexOptions.IgnoreCase)

Me.TextBox1.Text = MyReg.Replace(Me.TextBox1.Text, AddressOf Capitalize)

End Sub

Private Function Capitalize(ByVal m As System.Text.RegularExpressions.Match)
As String

If m.Value.Length > 1 Then

Capitalize = m.Value.Substring(0, 1).ToUpper & m.Value.Substring(1)

Else

Capitalize = m.Value.ToUpper

End If

End Function
 
Back
Top