c# - How to tell count of non-empty strings in string array -
i have string pipe delimited:
string line = "test|||tester||test||||||test test|"
i reading intro string array:
string[] wordsarr = line.split(new string[] { "|" }, stringsplitoptions.none);
my goal without manually writing loop myself if there way built framework see how many items in array not empty. can't utilize removeemptyentries
property on stringsplitoptions
b/c items fall within pipes matter.
any ideas?
if looking count, utilize .count
after split.
string line = "test|||tester||test||||||test test|"; int notemptycount = line .split('|') .count(x => !string.isnullorempty(x));
if want filter out items empty , access items remain, utilize .where
instead.
var notemptycollection = line .split('|') .where(x => !string.isnullorempty(x));
c# arrays string
No comments:
Post a Comment