I'm curious, how would you test a string and say "yep, that is a ma delimited list!" I'm not so worried about the 'ma delimited' part more that this string has more than one item in it?
Thanks, R.
I'm curious, how would you test a string and say "yep, that is a ma delimited list!" I'm not so worried about the 'ma delimited' part more that this string has more than one item in it?
Thanks, R.
Share Improve this question asked Jul 9, 2009 at 22:49 flavour404flavour404 6,31230 gold badges106 silver badges140 bronze badges 2- 1 Are you trying to determine the difference from a string that is a probable csv and one that is a probably sentence? If so, the answer may be much more plicated than merely checking for one or more mas. – Mike Commented Jul 9, 2009 at 23:20
- No, its not a sentence, but a list of items concatenated together, depending on a particular set of circumstances. – flavour404 Commented Jul 10, 2009 at 23:05
5 Answers
Reset to default 11How about:
stringObject.indexOf(",") >= 0
To check if the string has more than one item, try something like:
str.split(",").length > 1
... although, as suggested in a ment, correct parsing is likely to be bit more plicated than this for the general case.
Edit:
whoops, misread language as Java - sorry.
Be very careful if you are just splitting on a ma for a csv list as fields can actually contain mas and are encased by quotes i.e.
Name,Age
"doe, jane",18
"bob, jim",20
If it isn't for a csv perhaps you should be using an array or an object to hold the values?
You could also just go like:
var words = yourString.split(',');
for(var i=0;i<words.length;++i) {
doSomething(words[i]);
}
Another solution:
(string.split(",").length > 1)
Steve