String: first letter upper case

Messy, but hey if it works:)

Visual Basic:
Dim strMyName As String = "paul"

Dim strFirstLetter As String = Microsoft.VisualBasic.UCase(Microsoft.VisualBasic.Left(strMyName, 1))

strMyName = strFirstLetter & Microsoft.VisualBasic.Mid(strMyName, 2, Microsoft.VisualBasic.Len(strMyName) - 1)

MessageBox.Show(strMyName)
 
Here would a simple code that would do it using .NET only (using compatibility functions is not very good):
Visual Basic:
'create a new string builder
Dim sb As New System.Text.StringBuilder("some text")
'replace the first letter with its uppercase counterpart
sb = sb.Replace(sb.Chars(0), Char.ToUpper(sb.Chars(0)), 0, 1)
MessageBox.Show(sb.ToString)
 
Last edited:
i missed mutant's post before .. this code works:
Code:
private string UCFirst(string strName)
{
  System.Text.StringBuilder sb = new System.Text.StringBuilder(strName);
  sb = sb.Replace(sb[0], Char.ToUpper(sb[0]), 0, 1);
  return sb.ToString();
}

thanks!
 
As my post stated, it was messy and yes I agree with mutant re using .net features is preferred! But it was late, I knew how to do it the old way but now I now the new way so everyones a winner :)
 
Back
Top