none
string function(s) to change only first letter of string to Upper Case? RRS feed

  • Question

  • español needs to be converted to Español.

    thank you

    • Changed type hazz Monday, December 20, 2010 2:19 PM
    Monday, December 20, 2010 2:19 PM

Answers

  • From msdn

     

            Dim myString As String = "wAr aNd pEaCe"

            ' Creates a TextInfo based on the "en-US" culture.
            Dim myTI As System.Globalization.TextInfo = New System.Globalization.CultureInfo("en-US", False).TextInfo

            ' Changes a string to lowercase.
            Debug.WriteLine(String.Format("""{0}"" to lowercase: {1}", myString, myTI.ToLower(myString)))

            ' Changes a string to uppercase.
            Debug.WriteLine(String.Format("""{0}"" to uppercase: {1}", myString, myTI.ToUpper(myString)))

            ' Changes a string to titlecase.
            Debug.WriteLine(String.Format("""{0}"" to titlecase: {1}", myString, myTI.ToTitleCase(myString)))


    Subnet Calculator / Planner      Serial Port      Random
    Monday, December 20, 2010 2:33 PM
  • I like this..

    Private Shared Function UppercaseFirst(value As String) As String
    	' Check for empty string.
    	If String.IsNullOrEmpty(value) Then
    		Return String.Empty
    	End If
    	' Return char and concat substring.
    	Return Char.ToUpper(value(0)) & value.Substring(1)
    End Function
    • Marked as answer by hazz Monday, December 20, 2010 3:36 PM
    Monday, December 20, 2010 3:35 PM

All replies

  • MyString=UCase(Left(MyString,1)) & Rigth(MyString,MyString.Length-1)
    
    Monday, December 20, 2010 2:27 PM
  • From msdn

     

            Dim myString As String = "wAr aNd pEaCe"

            ' Creates a TextInfo based on the "en-US" culture.
            Dim myTI As System.Globalization.TextInfo = New System.Globalization.CultureInfo("en-US", False).TextInfo

            ' Changes a string to lowercase.
            Debug.WriteLine(String.Format("""{0}"" to lowercase: {1}", myString, myTI.ToLower(myString)))

            ' Changes a string to uppercase.
            Debug.WriteLine(String.Format("""{0}"" to uppercase: {1}", myString, myTI.ToUpper(myString)))

            ' Changes a string to titlecase.
            Debug.WriteLine(String.Format("""{0}"" to titlecase: {1}", myString, myTI.ToTitleCase(myString)))


    Subnet Calculator / Planner      Serial Port      Random
    Monday, December 20, 2010 2:33 PM
  • I like this..

    Private Shared Function UppercaseFirst(value As String) As String
    	' Check for empty string.
    	If String.IsNullOrEmpty(value) Then
    		Return String.Empty
    	End If
    	' Return char and concat substring.
    	Return Char.ToUpper(value(0)) & value.Substring(1)
    End Function
    • Marked as answer by hazz Monday, December 20, 2010 3:36 PM
    Monday, December 20, 2010 3:35 PM
  • But the other answers are as good, why do you only mark your own post and not the ones proposed by Hannes, I was already very careful not to take to much time on your questions.

    You answers them almost all yourself and mark them than as answer.

    You simply need no help.

     


    Success
    Cor
    Monday, December 20, 2010 3:48 PM
  • But the other answers are as good, why do you only mark your own post and not the ones proposed by Hannes, I was already very careful not to take to much time on your questions.

    You answers them almost all yourself and mark them than as answer.

    You simply need no help.

     


    Success
    Cor

    Hey Cor, don't worry.  One day they will need help and no one will bother looking at their question.

    Subnet Calculator / Planner      Serial Port      Random
    Monday, December 20, 2010 7:35 PM
  • Hi ALL,

    Just thought I'd throw this one in too. ProperCase

     

    Microsoft.VisualBasic.StrConv(exampleString, Microsoft.VisualBasic.VbStrConv. ProperCase )

     

    will make the first letter of every word in a string into a capital letter making the rest of the word lowercase, so for example;

    THE quick bRoWn FoX jumps OVER the lazy DOG.

    becomes.>>

    The Quick Brown Fox Jumps Over The Lazy Dog.

     

    Here it is within the code for one Button on a Form.>>


    Public Class Form1
    
      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
        Dim exampleString As String = "THE quick bRoWn FoX jumps OVER the lazy DOG."
        Dim result As String
    
        result = Microsoft.VisualBasic.StrConv(exampleString, Microsoft.VisualBasic.VbStrConv.ProperCase)
        MessageBox.Show(result)
    
      End Sub
    End Class

     

    You can use the shorter form of.>>

    result = StrConv(exampleString, VbStrConv.ProperCase)

    provided

    Microsoft.VisualBasic

    remains as an IMPORTED NameSpace.  :-)  :-D

     



    Regards,

    John

    Click this link to see how to insert a picture into a forum post.
    Monday, December 20, 2010 7:50 PM
  • I sincerely apologize.  I am usually very careful to mark answers and give credit and vote for helpful suggestions.

    It just so happened I received an answer that really did make the most sense and when I tried the proposed suggestions, they didn't provide the answer I was looking for.  In this case utf8/unicode character strings are involved as well.

    For someone else who may come in behind me to have the same question, I thought it fair in this one case to mark the answer that was the best one...kind of like Stackoverflow i guess.

    Again, my apologies. TheCrash and dbasnett have helped me so many times and I have always given them credit and marked their usually totally right on and appropriate answers as such.

    Again, my apologies.

    greg

    Monday, December 20, 2010 10:50 PM
  • I know this is old but for anyone else who may need this, what worked for me is...

    String Builder is the end right after the Next command.

    txtResults.Text = (sb.ToString())
    txtResults.Text = Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(txtResults.Text)



    Helpful nice guy

    Sunday, January 14, 2018 5:32 AM
  • I know this is old but for anyone else who may need this, what worked for me is...

    String Builder is the end right after the Next command.

    txtResults.Text = (sb.ToString())
    txtResults.Text = Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(txtResults.Text)



    Helpful nice guy

    That is pretty much the standard, here is a language extension method that can be called for either English or Spanish.

    Public Module StringExtensions
        <System.Diagnostics.DebuggerStepThrough()>
        <Runtime.CompilerServices.Extension()>
        Public Function ProperCaseEnglish(ByVal sender As String) As String
            Return ProperCase(sender, "en-US")
        End Function
        <System.Diagnostics.DebuggerStepThrough()>
        <Runtime.CompilerServices.Extension()>
        Public Function ProperCaseSpanish(ByVal sender As String) As String
            Return ProperCase(sender, "es-MX")
        End Function
        <System.Diagnostics.DebuggerStepThrough()>
        <Runtime.CompilerServices.Extension()>
        Public Function ProperCase(ByVal sender As String, ByVal CultureCode As String) As String
            Dim TI As System.Globalization.TextInfo = New System.Globalization.CultureInfo(CultureCode, False).TextInfo
            Return TI.ToTitleCase(sender.ToLower)
        End Function
    End Module


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Sunday, January 14, 2018 6:36 AM
    Moderator