多个键 [英] Multiple Keys

查看:58
本文介绍了多个键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用NameValueCollection,这是可能的:

my.Add(" 1"," VALUE");

my.Add(" 1", VALUE);

my.Add(" 2"," VALUE");

my.Add(" 2"," VALUE" );

另外,我如何迭代它并打印已经存储的值。

提前谢谢,

Shahid

解决方案

2005年6月13日星期一13:39:15 -0500,Shahid Juma< sh *********@gmail.com>

写道:

使用NameValueCollection,这是可能的:

my.Add(" 1"," VALUE");
my.Add(" 1"," VALUE");
my.Add(" 2"," VALUE");
my.Add(" 2"" VALUE");

另外,我如何遍历它并打印已经存在的值
存储。

提前致谢,
Shahid


是的,有可能,请注意NameValueCollection是

使用的QueryString属性(或从中返回)。如果你为已经存在的

键添加一个值,那么它将两个值连接在一起,在

之间(该值是以逗号分隔的列表) )。只有一个键名为

" 2"


一种迭代方式是有一个Keys属性可以迭代(注意)

我在我面前的这个例子是vb.net,你必须翻译成

C#):


Dim currval as String

For Each key As String in my.Keys

currVal = my.Item(key)

''note如果密钥是2,则密钥是2。我会得到VALUE,VALUE

下一页


-

Craig Deelsnyder

Microsoft MVP - ASP / ASP.NET


感谢您的回复。除了使用NameValueConnection之外,还有什么我可以做的吗?


再次感谢

Shahid


NameValueCollection可以通过

唯一键存储键/值对。你可以''添加''多值到

一键,例如

my.Add(" 1"," VALUE");

my.Add(" 1"," VALUE");

my.Add(" 2"," VALUE");

my.Add(" 2"," VALUE");


结果是它连接用逗号分隔的值,例如

my(" ; 1a ??)= a ?? VALUE,VALUEa ??看来你可以使用

string.split(",.ToCharArray())来获取一个值数组。但是假设有一个带逗号的值为
,例如" 1000" ;.你是如何处理它的?


Elton Wang
el ** ******@hotmail.com

" Shahid Juma"写道:

使用NameValueCollection,这是可能的:

my.Add(" 1"," VALUE");
我的。添加(1,VALUE);
my.Add(" 2"," VALUE");
my.Add(" 2"," VALUE") ;

另外,如何迭代它并打印已存储的值。

提前谢谢,
Shahid



Using NameValueCollection, is this possible:
my.Add ("1", "VALUE");
my.Add ("1", "VALUE");
my.Add ("2", "VALUE");
my.Add ("2", "VALUE");
Also, how do I iterate through it and print the values that have been
stored.
Thanks in advance,
Shahid

解决方案

On Mon, 13 Jun 2005 13:39:15 -0500, Shahid Juma <sh*********@gmail.com>
wrote:

Using NameValueCollection, is this possible:
my.Add ("1", "VALUE");
my.Add ("1", "VALUE");
my.Add ("2", "VALUE");
my.Add ("2", "VALUE");
Also, how do I iterate through it and print the values that have been
stored.
Thanks in advance,
Shahid



Yes it is possible, note also that NameValueCollection is what''s used by
the QueryString property (or returned from it). If you add a value for
key that''s already there, it then concatenates the 2 values with a , in
between (the value is a comma-separated list). There''s only 1 key named
"2".

One way of iterating is that there''s a Keys property to iterate over (note
this example I have in front of me is vb.net, you''ll have to translate to
C#):

Dim currval as String
For Each key As String In my.Keys
currVal = my.Item(key)
''note if key was "2" I''d get "VALUE,VALUE"
Next

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET


Thanks for the reply. Is there anything else that I can do to achieve
the above besides using NameValueConnection?

Thanks again
Shahid


NameValueCollection can store key/value pairs by
unique keys. you can ''Add'' multi-values to
one key, e.g.
my.Add ("1", "VALUE");
my.Add ("1", "VALUE");
my.Add ("2", "VALUE");
my.Add ("2", "VALUE");

The result is that it concatenates values separated by comma, e.g.
my("1a??) = a??VALUE,VALUEa??. It seems you can use
string.split(",".ToCharArray()) to get an value array. But suppose there is
one value with comma, e.g. "1,000". How do you deal with it?

Elton Wang
el********@hotmail.com
"Shahid Juma" wrote:

Using NameValueCollection, is this possible:
my.Add ("1", "VALUE");
my.Add ("1", "VALUE");
my.Add ("2", "VALUE");
my.Add ("2", "VALUE");
Also, how do I iterate through it and print the values that have been
stored.
Thanks in advance,
Shahid



这篇关于多个键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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