Select certain parts of a text box to print out?

Squad08

New member
Joined
Oct 11, 2007
Messages
4
Programming Experience
Beginner
I am creating a program where there is 1 text box and only 1 text box where the user inputs their full name. (ex. George Bean Banana) and when you click the initialize button the display is ( G. B. B.). So far I have it so it will Display ( G. ) but I can not figure out how to get the beginning of the second word in the box and the beginning of the third word in the box.

I was thinking that I would use the strName.indexOf(" ") somehow to find where the spaces are then just +1 to the location and display whats after the space. But I am not to sure on how I would go about using that? Any ideas would be greatly appreciated. Thank You.
 
Last edited:
VB.NET:
 intSecondInitial = strFullName.IndexOf(" ")
        Me.lblInitialAnswer.Text = (strFullName.Substring(0, 1) & ". " & strFullName.Substring(intSecondInitial, 2) & ". ")

Ok, so far this gets me the first and second Initials perfectly. The problem is I can no longer use strFullName.IndexOf(" ") because it will just give me the same one instead of the next spot of a " " (space). So is there a command that I can use to get the 2nd occuring space of strFullname.IndexOf(" ") like strFullName.IndexOf(" ", 2) or something?
 
Apparently I am a much better coder / thinker then I give myself credit for. I figured it all out myself by sitting here watching family guy and thinking about it. Thanks for letting me post here on the forums and keep me thinking on track! I can't believe I just figured it out!
 
More often than not when you figure something out, you should also post your answer incase others are having the same problem, they can find the solution easy ;)

The way i would do this, I don't know if you did or not is by splitting the text. so my code would look something like this:
VB.NET:
Me.lblInitialAnswer.Text = Split(strFullName, " ")(0).Substring(0, 1) & ". " & Split(strFullName, " ")(1).Substring(0, 1) & ". " & Split(strFullName, " ")(2).Substring(0, 1) & "."
 
VB.NET:
strFullName = Me.txtFullName.Text
        intSecondInitial = strFullName.IndexOf(" ")
        intThirdInitial = strFullName.IndexOf(" ", intSecondInitial + 1)
        Me.lblInitialAnswer.Text = (strFullName.Substring(0, 1) & ". " & strFullName.Substring(intSecondInitial, 2) & ". " & strFullName.Substring(intThirdInitial, 2) & ".")

That was my answer, I basically set to vaiables to the index of it so I could use them while using .SubString. Then What I did was figured that if I did intSecondInitial + 1 then it would put in the second iniditial index... which isn't what I wanted but then it would move 1 place forward because of the + 1. I didn't get a blue line, so I ran it and typed my full name in First Middle Last and then when I clicked the button I got my initials C. W. L.
 
Back
Top