|
Trying to use the split function, but one of the fields I am trying to load has "Last Name, First Name" (with double quotes around it. Is it posible to set an optionaly enclosed by parameter in the split function?
Common sense is admitting there is cause and effect and that you can exert some control over what you understand.
|
|
|
|
|
Thanks
Common sense is admitting there is cause and effect and that you can exert some control over what you understand.
|
|
|
|
|
wouldn't it be easier to:
strName.Replace("\"", "").Split(...)?
|
|
|
|
|
Not if he wants the name to stay whole (which I assume to be the case). That [what Sledge suggests] seems like a bad idea in general.
modified 27-Dec-12 18:37pm.
|
|
|
|
|
Your assumption is correct. Needed the whole name. To get it done, I changed the delimiter in the data from a comma to a tilde. It worked users are happy for the moment.
(Edit) Part of the conversion process is breaking the name apart into first name last name
Common sense is admitting there is cause and effect and that you can exert some control over what you understand.
|
|
|
|
|
I don't get it. You have a string as "Last Name, First Name" and you want Last Name, First Name without the quotes? Then just strip off the quotes. There is no need to use the split function. Since you want to break the name apart, my solution is actually correct. Remove the quotes, then split based on the comma.
|
|
|
|
|
No, that's just one of the fields. Check out some troublesome data:
id,name,location,phone
1,"Smith, John","Anytown, USA",123-4567
2,William "The Refrigerator" Perry,The Gridiron,000-0000
3,Madonna,"Los Feliz, Los Angeles, CA",555-5555
Not to say that the OP has such problems with which to deal, but some do.
modified 27-Dec-12 22:19pm.
|
|
|
|
|
I don't recall seeing that in the original post. I went back and re-read it, and if that is what the OP had intended, its a very poorly worded question . In this case, I'd:
string[] parts = Split(',')
foreach (string in parts)
Replace("\"", "");
Personally, parts 1 and 2 need special comma handling and parts 0 and 3 don't.
If I wanted to get sophisticated, I believe you can use datasets to parse something like that for you, but I'd just do what I said above... split on the commas, strip off the quotes and then process the 4 fields.
|
|
|
|
|
William "The Refrigerator" Perry and Madonna say that's a bad idea.
Without more knowledge of the data, the only proper way to handle this is to split on the delimiters while honoring the quotes.
Replace is rarely an appropriate tool.
|
|
|
|
|
SledgeHammer01 wrote: its a very poorly worded question
Those are some of the lines I've become better at reading between. If it were that simple, the question wouldn't have been asked (by this particular asker).
|
|
|
|
|
Oh, NM... I see his issue now.
|
|
|
|
|
This is actually what I would've done too - it's seems simpler.
But then there are also multiple fields involved.
April
Comm100 - Leading Live Chat Software Provider
modified 27-May-14 8:35am.
|
|
|
|