|
-
March 21st, 2011, 12:39 PM
#5
Re: Returning a Value
Hmmm, I see ...
you're saying that the first and last names may change position within "nameString" ?
So in one case I might be looking at names like "Steve Jensen" and then in another case I'd be seeing names in reverse order such as "Jensen, Steve" ?
Ahhh, in that case, forgive me, Sir. When I looked at your code you seemed to just be iterating through the string looking for a space.
My immediate thought was to forget the iterating and let Microsoft do the heavy lifting ... let the Regex engine iterate through the namestring and capture the first token it saw, assuming that would be the first name ... but certainly not in a situation where the name is in reverse order.
Indeed, I might have suggested an alternative .... forget the FOR loop and just do a string.Split on a space (on a trim()'ed string, of course) .... but even then you wouldn't know which of the two-element array returned would be the first name without first analyzing them.
(And, hopefully, it would be only a two-element array ... it might be more if there are two or more spaces inbetween the first and last name).
Ya know, it's entirely possible that my block of code is responsible for the confusion.
Although I am clearly SETTING nameString to a value (as you do in your code), it was not my intent to suggest that you would set it to a literal. That's just to set nameString to something so that you can try the three line block of code on your machine.
On the contrary, you would continue to set nameString as you normally do. The important part of that code block is the regular expression definition, and its use in the Regex match statement. I believe it will capture the first token it sees. Whether that's a first name or a surname is irrelevant - it doesn't know about names, it knows only tokens.
Try the block of code on your machine ... I think it'll work for ya.
Sorry 'bout that ... sorry for wasting your time.
Old Fool
Last edited by ThermoSight; March 21st, 2011 at 01:04 PM.
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
|