Visual Basic Help (String Manipulation)

lil layzie

Gawd
Joined
Jan 7, 2004
Messages
755
In one of my exercises, I have to code an application that allows the user to enter a first and last name. The application should then display the name in a label (last name followed by a comma then space and the first name with the proper case). The first letter of the first and last name should be an uppercase letter and the remaining letters should be lowercase when displayed no matter how the user types the name.

I figured that I would first make the entire first and last name all lowercase then just capitalize the first letter in the first and last name. The problem is how would I make the application understand where to capitalize the first letter in the first and last name?

Here is an part of my code:
Code:
firstName = fullName.Substring(0, indexNum)
firstName = firstName.ToLower()
lastName = fullName.Substring(indexNum)
lastName = lastName.ToLower()
 
I believe the System.Globalization library has a method to properly case words -

But, that's probably not acceptable for the class :)

Substring takes two inputs (well, I'm sure it's overloadable, but for this case, you need two):

Start character, # of characters.

So to get just the first letter, and capitalized, you'd go
String firstLetterOfFirstName = firstName.Substring(0,1).ToUpper();

From there I'm sure you can figure out how to concatenate it back with the rest of the firstname (Substring(1, firstName.Length-1))
 
Back
Top