Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Character equivalent of elements in an Enumeration

Status
Not open for further replies.

ashishraj14

Programmer
Mar 1, 2005
92
AU
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
 
Code:
Public Class Delimiters
    Public Shared ReadOnly Property Tab() As Char
        Get
            Return ControlChars.Tab
        End Get
    End Property
    Public Shared ReadOnly Property SemiColon() As Char
        Get
            Return Convert.ToChar(";")
        End Get
    End Property
End Class
...
etc.

Use as
Dim c As Char = Delimiters.SemiColon
 
RiverGuy

Enum Delimiters is used in property as follows, which allows user to set a delimiter. How would creating a class help?

Public Property Delimiter() As Delimiters
Get
Return m_enmDelimiter
End Get
Set(ByVal Value As Delimiters)
m_enmDelimiter = Value
End Set
End Property
 

Use Asc value of each character in the Enum as follows

Public Enum Delimiters
Tab = Asc(vbTab)
Semicolon = Asc(";")
Comma = Asc(",")
Space = Asc(" ")
End Enum

Then simply retrieve the character using

Dim strDelimiter As String = Chr(Delimiters.Semicolon)

You can also use actual numeric values instead of Asc values

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top