Character equivalent of elements in an Enumeration

G

Guest

I have an enumeration as follows

Public Enum Delimiters
Tab
Semicolon
Comma
Space
End Enum

How can I return character equivalent of the elements in the enumeration?

Should I write a Function which checks each element and return character
equivalent or is there any other way as well?

Thanks
 
C

Cor Ligthert

Job,

You use the enum while you are programming, what is the goal you want to
reach with this enum.

Cor
 
J

Jay B. Harlow [MVP - Outlook]

Job,
Normally when I need character constants I use character constants instead
of an Enum.

Something like:

Public Notinheritable Class Delimiters

Const Tab As Char = ControlChars.Tab
Const Semicolon As char = ";"c
Const Comma As Char = ","c
Const Space As Char = " "c

Private Sub New()
End Sub

End Class

The "Notinheritable" prevents any one from inheriting from this class, the
"Private Sub New" prevents any one from instantiating this class.

NOTE: I normally put the above in the class where they are needed, not in
their own class...

If I "really" needed/wanted an Enum, I would consider using the AscW code of
the characters then use ChrW to get Characters out. However! I would
seriously consider the above constants first!

Something like:

Public Enum Delimiters

Tab = AscW(ControlChars.Tab)
Semicolon = AscW(";"c)
Comma = AscW(","c)
Space = AscW(" "c)

End enum

Dim ch As Char = ChrW(Delimiters.Tab)


Hope this helps
Jay

|I have an enumeration as follows
|
| Public Enum Delimiters
| Tab
| Semicolon
| Comma
| Space
| End Enum
|
| How can I return character equivalent of the elements in the enumeration?
|
| Should I write a Function which checks each element and return character
| equivalent or is there any other way as well?
|
| Thanks
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top