Parsing Names for From Flags Enumerated Value, removing Spaces

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a more effcient way of removing the spaces from the names for a
Enumerated value that has several values when you split it)???

When you do a toString it puts ,<SPACE> between the entries

eg. category.ToString() = "cat1, cat2, cat3"

What I am currently doing..(and I use this a lot..)

this.categoriesEntry.Items.AddRange(
category.ToString().Replace(" ",String.Empty).Split(new char[]{','})
);
 
Mike,

Looking at the overrides for the ToString method, it doesn't look like
there is a better way to do that. You could enumerate through the values,
and write the string yourself, but it seems easier to just do the replace
(although I imagine it is less efficient).

It's easy enough to place this sort of code into a helper function which
would return the appropriate string to you.

Hope this helps.
 
Back
Top