|
-
Dec 1st, 2011, 11:55 PM
#1
Lively Member
Re: Please Help with Visual Studios 2010 Assignment
Oops, sorry about the errors. I just realized you are making a console application so you can't use message boxes. In my code you will have to replace "msgbox" with "Console.WriteLine", then it should work.
There are a couple ways to do the second part of your assignment. I will teach you one way...
First we will get the input string. Here you will use Console.ReadLine to read the input, but I will just do this:
vb Code:
Dim inputstring As String = "Print all employee data"
Then we need to split the input string into words. The best way to do that is use the String.Split method, and we will split the string by spaces " " .
vb Code:
Dim inputSplit As String() = inputstring.Split(" ")
inputSplit is now a collection of strings. inputSplit(0) is "Print". inputSplit(1) is "all". inputSplit(2) is "employee". inputSplit(3) is "data".
We can now loop through each word/string inside of inputSplit like this:
vb Code:
For Each word As String In inputSplit 'do stuff Next
Now that we can loop through each word, we need to take each word and capitalize the first character, then store it in a new string.
To get the first character of a string you can use String.Substring(0,1) and that will start at character 0, and take 1 character. So that means "employee".Substring(0,1) = "e". Then you can just call String.ToUpper and capitalize it.
To get all characters after the first character you can use String.Substring(1) and that will start at character 1 and take everything after it. So that means "employee".Substring(1) = "mployee".
So.... "employee".Substring(0,1).toUpper & "employee".Substring(1) = "Employee" . We can now add something similar to the loop.
vb Code:
Dim newString as string = "" For Each word As String In inputSplit newString += word.Substring(0,1).toUpper & word.Substring(1) Next
When the loop finishes, newString will be "PrintAllEmployeeData"
Now you just have to take the first character of newString and make it lower case, and you are finished. I'm sure you can figure out how to do that now.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|