• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

VB.net Assistance in splitting up contents of a text box

This may be more complex than you think. I do something very similar in a VBA program for Excel. For my purposes, I just need to extract the last name. So, I look for the first space in the string using the InStr (in string) function. That gives me the position of the space, then I take the right side of the string from the location of the space. It is only two lines of code (I don't know if the functions are identical in VB):

Pos = InStr(Name, " ")
Last= Right(Name, Len(Name) - Pos)

This works fine for me, but I don't need absolute perfection. There are a ton of potential problems. For example, what if somebody types in "Bob F. Jones" instead of "Bob Jones"? Then, using my code you will get "F. Jones" for the last name. There are other potential errors as well.

I think you might be better off having two text boxes (First and Last) rather than just one for the name. This will be much easier than coming up with an algorithm that will work in every conceivable case.
 
Doesn't VB still have the Split function? Pass it a string and a delimiter and you're returned an array of results.

mayest is right though, you're just asking for unpredictable results.
 
Originally posted by: mayest
This may be more complex than you think. I do something very similar in a VBA program for Excel. For my purposes, I just need to extract the last name. So, I look for the first space in the string using the InStr (in string) function. That gives me the position of the space, then I take the right side of the string from the location of the space. It is only two lines of code (I don't know if the functions are identical in VB):

Pos = InStr(Name, " ")
Last= Right(Name, Len(Name) - Pos)

This works fine for me, but I don't need absolute perfection. There are a ton of potential problems. For example, what if somebody types in "Bob F. Jones" instead of "Bob Jones"? Then, using my code you will get "F. Jones" for the last name. There are other potential errors as well.

I think you might be better off having two text boxes (First and Last) rather than just one for the name. This will be much easier than coming up with an algorithm that will work in every conceivable case.

:thumbsup:
 
Back
Top