Question about split
-
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.
-
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.
-
-
wouldn't it be easier to: strName.Replace("\"", "").Split(...)?
-
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.
-
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.
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.
-
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.
-
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-5555Not to say that the OP has such problems with which to deal, but some do.
-
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.
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
-
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-5555Not to say that the OP has such problems with which to deal, but some do.
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.
-
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
andMadonna
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. -
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.
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).
-
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... actually, I just re-read the OPs post. We have BOTH misinterpreted it. His issue is that: a,b,"c,d",e is getting split by comma as a,b,c,d,e instead of c,d getting split as a single item. That has nothing to do with Replace or stripping quotes. That's simply an issue of Split doing what its supposed to do. Splitting on the comma. Split is the issue here, not Replace. Assuming data is never misformed, he'd have to "escape" the commas inside of double quotes. Which is what he did. This is why you shouldn't use CSV files in general. TSV or PSV files are much less likely to run into this problem. The PROPER solution when using CSV, TSV or PSV files is to escape separators when WRITING if they occur in your string. Much like having a < or > is not valid XML.
-
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.