Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Messy, but hey if it works:)

 


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)

My website
  • *Experts*
Posted (edited)

Here would a simple code that would do it using .NET only (using compatibility functions is not very good):

'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)

Edited by mutant
Posted

i missed mutant's post before .. this code works:

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!

Posted
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 :)
My website

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...