By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,041 Members | 1,099 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,041 IT Pros & Developers. It's quick & easy.

Emum to String

P: n/a
Hello All:

I have the following Emuneration which I am using in my Web Application

Enum ROLE As Integer

APPLICATION_VIEWER = 1
USER_GROUP_ADMIN = 2
SECURITY = 4
NODE_ADMIN = 8
ADMIN = 16
POWER_USER = 32
USER = 64

End Enum

If I have BitMask how do I return the Value so I can use it as a String
which looks like this

65 = APPLICATION_VIEWER|USER
41 = APPLICATION_VIEWER|NODE_ADMIN|POWER_USER

Thanks
Stuart
Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi,

Apply the FlagsAttribute on the enumeration. Then calling ToString() on the
ROLE type variable will return you the comma seaprated list of individual
bit masks. For example:

<Flags> _
Enum ROLE As Integer
APPLICATION_VIEWER = 1
USER_GROUP_ADMIN = 2
SECURITY = 4
NODE_ADMIN = 8
ADMIN = 16
POWER_USER = 32
USER = 64
End Enum

Dim a As ROLE
a = ROLE.APPLICATION_VIEWER Or ROLE.USER_GROUP_ADMIN

Now, a.ToString() will return "APPLICATION_VIEWER, USER_GROUP_ADMIN". You
can then replace all ', ' occurances with '|'.

Hope, I got your question correctly.
"Stuart Shay" <ss***@j51.com> wrote in message
news:eX**************@tk2msftngp13.phx.gbl...
Hello All:

I have the following Emuneration which I am using in my Web Application

Enum ROLE As Integer

APPLICATION_VIEWER = 1
USER_GROUP_ADMIN = 2
SECURITY = 4
NODE_ADMIN = 8
ADMIN = 16
POWER_USER = 32
USER = 64

End Enum

If I have BitMask how do I return the Value so I can use it as a String
which looks like this

65 = APPLICATION_VIEWER|USER
41 = APPLICATION_VIEWER|NODE_ADMIN|POWER_USER

Thanks
Stuart

Nov 20 '05 #2

P: n/a
Shiva

Thanks, But I need the reverse, I have a method that returns 41 and I need
to Convert this to the String APPLICATION_VIEWER|NODE_ADMIN|POWER_USER

Example

Input: 41
Output: APPLICATION_VIEWER|NODE_ADMIN|POWER_USER

Input 65
Output: APPLICATION_VIEWER|USER

<Flags> _
Enum ROLE As Integer
APPLICATION_VIEWER = 1
USER_GROUP_ADMIN = 2
SECURITY = 4
NODE_ADMIN = 8
ADMIN = 16
POWER_USER = 32
USER = 64
End Enum

Thanks
Stuart
"Shiva" <sh******@online.excite.com> wrote in message
news:uJ**************@TK2MSFTNGP12.phx.gbl...
Hi,

Apply the FlagsAttribute on the enumeration. Then calling ToString() on
the
ROLE type variable will return you the comma seaprated list of individual
bit masks. For example:

<Flags> _
Enum ROLE As Integer
APPLICATION_VIEWER = 1
USER_GROUP_ADMIN = 2
SECURITY = 4
NODE_ADMIN = 8
ADMIN = 16
POWER_USER = 32
USER = 64
End Enum

Dim a As ROLE
a = ROLE.APPLICATION_VIEWER Or ROLE.USER_GROUP_ADMIN

Now, a.ToString() will return "APPLICATION_VIEWER, USER_GROUP_ADMIN". You
can then replace all ', ' occurances with '|'.

Hope, I got your question correctly.
"Stuart Shay" <ss***@j51.com> wrote in message
news:eX**************@tk2msftngp13.phx.gbl...
Hello All:

I have the following Emuneration which I am using in my Web Application

Enum ROLE As Integer

APPLICATION_VIEWER = 1
USER_GROUP_ADMIN = 2
SECURITY = 4
NODE_ADMIN = 8
ADMIN = 16
POWER_USER = 32
USER = 64

End Enum

If I have BitMask how do I return the Value so I can use it as a String
which looks like this
65 = APPLICATION_VIEWER|USER

41 = APPLICATION_VIEWER|NODE_ADMIN|POWER_USER

Thanks
Stuart

Nov 20 '05 #3

P: n/a
Ok, you can declare a variable of type ROLE and assign the numeric value to
it directly. Eg:

Dim a As Role
Dim s As String
a = 41
s = a.ToString().Replace (", ", "|")
Console.WriteLine (s) 'Prints APPLICATION_VIEWER|NODE_ADMIN|POWER_USER

Hope I got it correctly now :-)

"Stuart Shay" <ss***@j51.com> wrote in message
news:ec*************@TK2MSFTNGP11.phx.gbl...
Shiva

Thanks, But I need the reverse, I have a method that returns 41 and I need
to Convert this to the String APPLICATION_VIEWER|NODE_ADMIN|POWER_USER

Example

Input: 41
Output: APPLICATION_VIEWER|NODE_ADMIN|POWER_USER

Input 65
Output: APPLICATION_VIEWER|USER

<Flags> _
Enum ROLE As Integer
APPLICATION_VIEWER = 1
USER_GROUP_ADMIN = 2
SECURITY = 4
NODE_ADMIN = 8
ADMIN = 16
POWER_USER = 32
USER = 64
End Enum

Thanks
Stuart
"Shiva" <sh******@online.excite.com> wrote in message
news:uJ**************@TK2MSFTNGP12.phx.gbl...
Hi,

Apply the FlagsAttribute on the enumeration. Then calling ToString() on
the
ROLE type variable will return you the comma seaprated list of individual
bit masks. For example:

<Flags> _
Enum ROLE As Integer
APPLICATION_VIEWER = 1
USER_GROUP_ADMIN = 2
SECURITY = 4
NODE_ADMIN = 8
ADMIN = 16
POWER_USER = 32
USER = 64
End Enum

Dim a As ROLE
a = ROLE.APPLICATION_VIEWER Or ROLE.USER_GROUP_ADMIN

Now, a.ToString() will return "APPLICATION_VIEWER, USER_GROUP_ADMIN". You
can then replace all ', ' occurances with '|'.

Hope, I got your question correctly.
"Stuart Shay" <ss***@j51.com> wrote in message
news:eX**************@tk2msftngp13.phx.gbl...
Hello All:

I have the following Emuneration which I am using in my Web Application

Enum ROLE As Integer

APPLICATION_VIEWER = 1
USER_GROUP_ADMIN = 2
SECURITY = 4
NODE_ADMIN = 8
ADMIN = 16
POWER_USER = 32
USER = 64

End Enum

If I have BitMask how do I return the Value so I can use it as a String
which looks like this
65 = APPLICATION_VIEWER|USER

41 = APPLICATION_VIEWER|NODE_ADMIN|POWER_USER

Thanks
Stuart


Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.