Piped将字符串分隔为int [英] Piped delimited string to int

查看:68
本文介绍了Piped将字符串分隔为int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我试图用以下签名调用一个方法:


AddRole(string Group_Nam,string Description,int permissionmask);


加密到msdn,你可以使用管道符号屏蔽权限。对于

例子你可以使用这样的东西


AddRole(" My Group"," Test",0x10000000 | 0x00000002);


Porblem是,我从一个复选框列表获取此权限掩码,我将
存储在其value属性中的所有这些数字(如0x00000002)。当使用

选择多个复选框时,我动态生成一个管道分隔的字符串

当我将其转换为int时(使用

int.Parse( my_pipe_delimited_string)或

Convert.Int32(my_pipe_delimited_string))我得到对象引用集对象

引用未设置为对象的实例。


如果我在方法中提到0x10000000 | 0x00000002,那很好,但是它似乎我不能从用户的输入中动态生成它。


您的帮助非常感谢。


再见

Hello ,

I am trying to call a mthod with the following signature:

AddRole(string Group_Nam, string Description, int permissionmask);

Accroding to msdn ,you can mask the permissions using pipe symbol .for
example you can use something like this

AddRole("My Group", "Test", 0x10000000|0x00000002);

Porblem is ,I am getting this permission mask from a checkboxlist and I have
stored all these numbers (like 0x00000002) in its value property. When use
selects multiple checkboxes I dynamically generate a pipe delimited string
and when I convert it to int (either using
int.Parse(my_pipe_delimited_string) or
Convert.Int32(my_pipe_delimited_string)) I get object reference set "Object
reference not set to an instance of an object".

if I just mention 0x10000000|0x00000002 in the method that''s fine ,but it
seems I cannot dynamically generate it from the user''s input.

Your help is much appreciate.

Bye

推荐答案

Fariba <发**** @ fariba.com>写道:
Fariba <Fa****@fariba.com> wrote:
我试图用以下签名调用一个方法:

AddRole(字符串Group_Nam,字符串描述,int permissionmask);

加载到msdn,您可以使用管道符号屏蔽权限。例如,您可以使用类似的东西

AddRole(我的组,测试,0x10000000 | 0x00000002) ;


是的,但那是'C#语法 - 它只是按位做或。

Porblem是,我得到了复选框列表中的此权限掩码,我已将所有这些数字(如0x00000002)存储在其value属性中。当使用
选择多个复选框时,我动态生成一个管道分隔的字符串
当我将其转换为int时(使用
int.Parse(my_pipe_delimited_string)或
Convert.Int32(my_pipe_delimited_string) ))我得到对象引用集对象
引用未设置为对象的实例。

如果我在方法中提到0x10000000 | 0x00000002,那很好,但是它似乎无法从用户的输入中动态生成它。
I am trying to call a mthod with the following signature:

AddRole(string Group_Nam, string Description, int permissionmask);

Accroding to msdn ,you can mask the permissions using pipe symbol .for
example you can use something like this

AddRole("My Group", "Test", 0x10000000|0x00000002);
Yes, but that''s the C# syntax - it''s just doing a bitwise "or".
Porblem is ,I am getting this permission mask from a checkboxlist and I have
stored all these numbers (like 0x00000002) in its value property. When use
selects multiple checkboxes I dynamically generate a pipe delimited string
and when I convert it to int (either using
int.Parse(my_pipe_delimited_string) or
Convert.Int32(my_pipe_delimited_string)) I get object reference set "Object
reference not set to an instance of an object".

if I just mention 0x10000000|0x00000002 in the method that''s fine ,but it
seems I cannot dynamically generate it from the user''s input.




您需要将每个值转换为int,和或那些。我建议您在复选框选择部分执行此操作,只需将每个选中值的或 - 结果存储在

结果中。


-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet 博客: http://www.msmvps.com/jon.skeet

如果回复该群组,请不要给我发邮件



You''ll need to convert each of the values to an int, and "or" those. I
suggest you do that at the checkbox selection part, storing just the
result of "or"-ing together each of the checked values.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too




" Fariba" <发**** @ fariba.com>在消息中写道

新闻:%2 **************** @ TK2MSFTNGP03.phx.gbl ...

"Fariba" <Fa****@fariba.com> wrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
您好,

我正在尝试使用以下签名调用方法:

AddRole(字符串Group_Nam,字符串描述,int权限掩码);

累积到msdn,您可以使用管道符号屏蔽权限。例如,您可以使用类似的东西

AddRole(我的组,测试,0x10000000 | 0x00000002); <是的,我正在从一个复选框列表中获取此权限掩码,并且我已将所有这些数字(如0x00000002)存储在其value属性中。
使用时选择多个复选框我是动态的生成一个管道
分隔的字符串,当我将其转换为int(使用
int.Parse(my_pipe_delimited_string)或
Convert.Int32(my_pipe_delimited_string))我得到对象引用集
对象引用未设置为对象的实例。

如果我只提0 x10000000 | 0x00000002在方法中很好,但它似乎无法从用户的输入中动态生成它。

非常感谢你的帮助。
Hello ,

I am trying to call a mthod with the following signature:

AddRole(string Group_Nam, string Description, int permissionmask);

Accroding to msdn ,you can mask the permissions using pipe symbol .for
example you can use something like this

AddRole("My Group", "Test", 0x10000000|0x00000002);

Porblem is ,I am getting this permission mask from a checkboxlist and I
have stored all these numbers (like 0x00000002) in its value property.
When use selects multiple checkboxes I dynamically generate a pipe
delimited string and when I convert it to int (either using
int.Parse(my_pipe_delimited_string) or
Convert.Int32(my_pipe_delimited_string)) I get object reference set
"Object reference not set to an instance of an object".

if I just mention 0x10000000|0x00000002 in the method that''s fine ,but it
seems I cannot dynamically generate it from the user''s input.

Your help is much appreciate.




正确的方法是直接修改一个int。


const int Flag1 = 0x100000000;

int flags;


// on check

flags | = Flag1;


//取消选中

flags& = ~Flag1;

//更好更好


[标志]

enum MyFlags

{

Flag1 = 0x1000000,

Flag2 = 0x1000001,

......

}


MyFlags标志;


//完全相同的代码用于检查和取消选中然后转换为int用于方法

调用(理想情况下应更改为使用枚举。


请注意,如果你使用带有FlagsAttribute的枚举,那么ToString()将

给你一个像Flag1 | Flag2这样的字符串。这使得调试变得更加容易。


另外 - 如果你将复选框的Tag属性设置为标志值然后

你可以做到没有任何丑陋条件代码或事件处理程序的加载。



The right way to do this is to modity an int directly.

const int Flag1 = 0x100000000;
int flags;

// on check
flags |= Flag1;

// on uncheck
flags &= ~Flag1;
// better still

[Flags]
enum MyFlags
{
Flag1 = 0x1000000,
Flag2 = 0x1000001,
......
}

MyFlags flags;

// exact same code for check and uncheck then cast to int for the method
call (which should ideally be changed to use the enum anyway.

Note that if you use an enum with the FlagsAttribute then ToString() will
give you a string like "Flag1|Flag2" which makes debugging much easier.

Also - if you set the Tag property of the check box to the flag value then
you can do it without any ugly conditional code or loads of event handlers.


On Sun,2006年4月16日00:03:10 -0700,Fariba。 <发**** @ fariba.com>写了

in<#3 ************** @ TK2MSFTNGP03.phx.gbl>:
On Sun, 16 Apr 2006 00:03:10 -0700, "Fariba" <Fa****@fariba.com> wrote
in <#3**************@TK2MSFTNGP03.phx.gbl>:
我是尝试使用以下签名调用方法:

AddRole(字符串Group_Nam,字符串描述,int权限掩码);

编写到msdn,您可以使用管道符号屏蔽权限。例如,你可以使用这样的东西

AddRole(我的组,测试,0x10000000 | 0x00000002);

Porblem是,我从复选框列表中获取此权限掩码,并且我已将所有这些数字(如0x00000002)存储在其value属性中。当使用
选择多个复选框时,我动态生成一个管道分隔的字符串
当我将其转换为int时(使用
int.Parse(my_pipe_delimited_string)或
Convert.Int32(my_pipe_delimited_string) ))我得到对象引用集对象
引用未设置为对象的实例。
I am trying to call a mthod with the following signature:

AddRole(string Group_Nam, string Description, int permissionmask);

Accroding to msdn ,you can mask the permissions using pipe symbol .for
example you can use something like this

AddRole("My Group", "Test", 0x10000000|0x00000002);

Porblem is ,I am getting this permission mask from a checkboxlist and I have
stored all these numbers (like 0x00000002) in its value property. When use
selects multiple checkboxes I dynamically generate a pipe delimited string
and when I convert it to int (either using
int.Parse(my_pipe_delimited_string) or
Convert.Int32(my_pipe_delimited_string)) I get object reference set "Object
reference not set to an instance of an object".




[snip rest]


你基本上误解了你在做什么。你好b / b
不是管道从一个程序到命令shell中的另一个程序的输入管道输出

的意义上的值。你是b $ b做一个数学运算,按位或两个或多个数字。


这是一个基本错误,我建议你停止你是b / b
做的,为初学程序员写一本关于C#的书,并在前几章阅读

。然后再读一遍。第三次无法受伤。在尝试编写有用的程序之前,您需要先了解基础知识。我知道它并没有像潜水那样有趣,但从长远来看,它将为你节省很多挫折和恶化。

。 >
-

Charles Calvert |软件设计/开发

Celtic Wolf,Inc。|项目管理
http://www.celticwolf.com/ |技术写作

(703)580-0210 |研究



[snip rest]

You have fundametally misunderstood what it is that you are doing. You
are not "piping" the values in the sense that one would pipe output
from one program to the input of another in a command shell. You are
doing a mathematical operation, bitwise-or, on two or more numbers.

This is such a basic mistake that I suggest you stop what you are
doing, grab a book on C# written for beginning programmers and read
the first few chapters. Then read them again. A third time couldn''t
hurt. You need to gain an understanding of the basics before trying
to write a useful program. I know it''s not as much fun as diving
right in, but it will save you a lot of frustration and aggravation in
the long run.
--
Charles Calvert | Software Design/Development
Celtic Wolf, Inc. | Project Management
http://www.celticwolf.com/ | Technical Writing
(703) 580-0210 | Research


这篇关于Piped将字符串分隔为int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆