Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. My code will not capitalize first letter of line

My code will not capitalize first letter of line

Scheduled Pinned Locked Moved Visual Basic
question
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jesi523
    wrote on last edited by
    #1

    My input text from a .txt file is this is the first line this is the second line this is the third line I need to capitalize the first letter of each word by placing it in a textbox, I have the following code: Dim aString As String = My.Computer.FileSystem.ReadAllText("input.txt") Dim stringReturn As String If My.Computer.FileSystem.FileExists("input.txt") Then Me.xInputTextBox.Text = (Convert.ToString(aString.ToLower)) End If Do While (aString.IndexOf(Space(2)) >= 0) aString = aString.Replace(Space(2), Space(1)) Loop Dim caparray() As String = (aString.Split(" " & "ControlChars.NewLine")) For I As Integer = 0 To caparray.Length - 1 If caparray(I).Length = 1 Then caparray(I) = caparray(I).ToUpper Else ' ***join them back together caparray(I) = caparray(I).Substring(0, 1).ToUpper & caparray(I).Substring(1).ToLower End If Next stringReturn = String.Join(" ", caparray) Me.xInputTextBox.Text = (stringReturn.ToString) My output is then This Is The First Line this Is The Second Line this Is The Third Line It will not capitalize the first letter of the second and third line. Can someone please tell me what I am doing wrong? Thanks, Jesi

    L D 2 Replies Last reply
    0
    • J Jesi523

      My input text from a .txt file is this is the first line this is the second line this is the third line I need to capitalize the first letter of each word by placing it in a textbox, I have the following code: Dim aString As String = My.Computer.FileSystem.ReadAllText("input.txt") Dim stringReturn As String If My.Computer.FileSystem.FileExists("input.txt") Then Me.xInputTextBox.Text = (Convert.ToString(aString.ToLower)) End If Do While (aString.IndexOf(Space(2)) >= 0) aString = aString.Replace(Space(2), Space(1)) Loop Dim caparray() As String = (aString.Split(" " & "ControlChars.NewLine")) For I As Integer = 0 To caparray.Length - 1 If caparray(I).Length = 1 Then caparray(I) = caparray(I).ToUpper Else ' ***join them back together caparray(I) = caparray(I).Substring(0, 1).ToUpper & caparray(I).Substring(1).ToLower End If Next stringReturn = String.Join(" ", caparray) Me.xInputTextBox.Text = (stringReturn.ToString) My output is then This Is The First Line this Is The Second Line this Is The Third Line It will not capitalize the first letter of the second and third line. Can someone please tell me what I am doing wrong? Thanks, Jesi

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      JessicaD523 wrote:

      This Is The First Line this Is The Second Line

      There is a newline but no space between Line and this, so to your algorithm they are just one word! A simple debug session would have told you that. You will have similar problems with punctuation: "aha" will be seen as a word starting with " not a. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google


      J 1 Reply Last reply
      0
      • L Luc Pattyn

        JessicaD523 wrote:

        This Is The First Line this Is The Second Line

        There is a newline but no space between Line and this, so to your algorithm they are just one word! A simple debug session would have told you that. You will have similar problems with punctuation: "aha" will be seen as a word starting with " not a. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google


        J Offline
        J Offline
        Jesi523
        wrote on last edited by
        #3

        Thank you, I kind of thought that was the problem...but how do i fix that? I'm very new at vb.net. Thanks. Jesi

        L 1 Reply Last reply
        0
        • J Jesi523

          Thank you, I kind of thought that was the problem...but how do i fix that? I'm very new at vb.net. Thanks. Jesi

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          Hi Jesi,

          JessicaD523 wrote:

          but how do i fix that?

          as always: 1. define the requirements as accurately as possible (what is a word, which words need capitalization, ...) 2. analyze, design, implement, test 3. iterate until satisfied. :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google


          1 Reply Last reply
          0
          • J Jesi523

            My input text from a .txt file is this is the first line this is the second line this is the third line I need to capitalize the first letter of each word by placing it in a textbox, I have the following code: Dim aString As String = My.Computer.FileSystem.ReadAllText("input.txt") Dim stringReturn As String If My.Computer.FileSystem.FileExists("input.txt") Then Me.xInputTextBox.Text = (Convert.ToString(aString.ToLower)) End If Do While (aString.IndexOf(Space(2)) >= 0) aString = aString.Replace(Space(2), Space(1)) Loop Dim caparray() As String = (aString.Split(" " & "ControlChars.NewLine")) For I As Integer = 0 To caparray.Length - 1 If caparray(I).Length = 1 Then caparray(I) = caparray(I).ToUpper Else ' ***join them back together caparray(I) = caparray(I).Substring(0, 1).ToUpper & caparray(I).Substring(1).ToLower End If Next stringReturn = String.Join(" ", caparray) Me.xInputTextBox.Text = (stringReturn.ToString) My output is then This Is The First Line this Is The Second Line this Is The Third Line It will not capitalize the first letter of the second and third line. Can someone please tell me what I am doing wrong? Thanks, Jesi

            D Offline
            D Offline
            Duane in Japan
            wrote on last edited by
            #5

            stringReturn = String.Join(" ", caparray) I do not have your answer but what does this String.Join do, is it joining the first line to the second line and so on? Can you use vbcrlf to go to the next line or 'proper case' instead of 'upper case'.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups