User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the VB.NET section within the Software Development category of DaniWeb, a massive community of 456,575 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,604 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our VB.NET advertiser: Programming Forums
Views: 2371 | Replies: 14 | Solved
Reply
Join Date: Oct 2007
Posts: 14
Reputation: Jesi523 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Jesi523 Jesi523 is offline Offline
Newbie Poster

Help Very new to VB.Net, please help

  #1  
Oct 26th, 2007
I am writing a program where I need to capitalize the first letter of each word in a text file. Example of information in the text file would be:

this is the first line
this is the second line
this is the third line

I have written a code that gives me back the following information:

This Is The First Line
this Is The Second Line
this Is The Third Line

I cannot figure out how to get the first word in the second and third lines capitalized.

I have used a split separator to create the array, the separator is a space. I know it is not capitaizing those letters because there is no space at the beginning of the line, but have no idea what to do to fix the problem. Can someone please help me? Thank you so much
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2005
Posts: 4,832
Reputation: iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light 
Rep Power: 17
Solved Threads: 324
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: Very new to VB.Net, please help

  #2  
Oct 26th, 2007
... the hat of 'is this a cat in a hat?'
Reply With Quote  
Join Date: Oct 2007
Posts: 14
Reputation: Jesi523 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Jesi523 Jesi523 is offline Offline
Newbie Poster

Help Re: Very new to VB.Net, please help

  #3  
Oct 26th, 2007
I forgot to mention that the information from the text file is going into the textbox, not another file.
Reply With Quote  
Join Date: Aug 2005
Posts: 4,832
Reputation: iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light 
Rep Power: 17
Solved Threads: 324
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: Very new to VB.Net, please help

  #4  
Oct 26th, 2007
In that case after you have capitalised the first letter of the line write it to the text box.

Did you want an example? Let me just fire up my windows box.
... the hat of 'is this a cat in a hat?'
Reply With Quote  
Join Date: Oct 2007
Posts: 14
Reputation: Jesi523 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Jesi523 Jesi523 is offline Offline
Newbie Poster

Help Re: Very new to VB.Net, please help

  #5  
Oct 26th, 2007
Yes, could you please give me an example. Thank you
Reply With Quote  
Join Date: Aug 2005
Posts: 4,832
Reputation: iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light 
Rep Power: 17
Solved Threads: 324
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: Very new to VB.Net, please help

  #6  
Oct 26th, 2007
Oopsie sorry about that. I was on my linux box

  1. Imports System.IO
  2.  
  3. Public Class Form1
  4.  
  5. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  6.  
  7. Dim objStreamReader As StreamReader
  8. Dim strLine As String
  9.  
  10. 'Pass the file path and the file name to the StreamReader constructor.
  11. objStreamReader = New StreamReader("C:\foo.txt")
  12.  
  13. 'Read the first line of text.
  14. strLine = objStreamReader.ReadLine
  15.  
  16. 'Continue to read until you reach the end of the file.
  17. Do While Not strLine Is Nothing
  18.  
  19. Dim bar As String
  20. If (strLine.Length > 0) Then
  21.  
  22. bar = strLine.Substring(0, 1).ToUpper & strLine.Substring(1, strLine.Length - 1)
  23.  
  24. 'Write the line to the textbox.
  25. TextBox1.Text = TextBox1.Text & bar & System.Environment.NewLine
  26. End If
  27. 'Read the next line.
  28. strLine = objStreamReader.ReadLine
  29. Loop
  30.  
  31. 'Close the file.
  32. objStreamReader.Close()
  33.  
  34. Console.ReadLine()
  35.  
  36. End Sub
  37. End Class

You probably have to select the multiline option on the text box...
Last edited by iamthwee : Oct 26th, 2007 at 4:46 pm.
... the hat of 'is this a cat in a hat?'
Reply With Quote  
Join Date: Aug 2005
Posts: 4,832
Reputation: iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light 
Rep Power: 17
Solved Threads: 324
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: Very new to VB.Net, please help

  #7  
Oct 26th, 2007
I have just edited the code so it is more robust when it comes to potential errors (such as blank lines in the file). You may need to refresh your browser to see it take effect.
Last edited by iamthwee : Oct 26th, 2007 at 4:45 pm.
... the hat of 'is this a cat in a hat?'
Reply With Quote  
Join Date: Oct 2007
Posts: 14
Reputation: Jesi523 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Jesi523 Jesi523 is offline Offline
Newbie Poster

Re: Very new to VB.Net, please help

  #8  
Oct 26th, 2007
Thank you so much I will try it.
Reply With Quote  
Join Date: Aug 2005
Posts: 4,832
Reputation: iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light 
Rep Power: 17
Solved Threads: 324
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: Very new to VB.Net, please help

  #9  
Oct 26th, 2007
let us know how you get on
... the hat of 'is this a cat in a hat?'
Reply With Quote  
Join Date: Oct 2007
Posts: 14
Reputation: Jesi523 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Jesi523 Jesi523 is offline Offline
Newbie Poster

Re: Very new to VB.Net, please help

  #10  
Oct 26th, 2007
It worked except now it will not capitalize the first letter of every word, it only capitalizes the first word of every line.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb VB.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the VB.NET Forum

All times are GMT -4. The time now is 6:14 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC