我有一个哈希表,他的value是这样的object.Tittle,都是有.的,我想把.两边的字符放进string数组
比如string[0]=object,string[1]=Tittle,string[2]=object1,string[3]=Tittle1...........
比如string[0]=object,string[1]=Tittle,string[2]=object1,string[3]=Tittle1...........
Hashtable ht = new Hashtable();
ht.Add("a", "a1");
ht.Add("b", "b1");
ht.Add("c", "c1");
ht.CopyTo(a, 0);
//转为string
string[] s = Array.ConvertAll<object, string>(a, delegate(object o) { return o == null ? "" : o.ToString(); });
{
string[] arr=o.ToString().Split('.');
}这样写只是获取了哈希表当前的值放进了数组,没有把整个都放进去,求解
Hashtable ht = new Hashtable();
ht.Add("a", "a1");
ht.Add("b", "b1");
ht.Add("c", "c1");
string[] s = new string[30];
ArrayList keyList = new ArrayList(ht.Keys);
ArrayList valueList = new ArrayList(ht.Values);
for (int i = 0; i < keyList.Count; i++)
{
s[i * 2] = keyList[i].ToString();
s[i * 2 + 1] = valueList[i].ToString();
}
ht.Add("a","object.Tittle")
ht.Add("b","object1.Tittle1")
放进数组的是s[0]="object";s[1]="Tittle"...........
是把ht的“值”截取了放数组,和Key没关系
Hashtable ht = new Hashtable();
ht.Add("a", "object.Tittle");
ht.Add("b", "object1.Tittle1");
foreach (DictionaryEntry v in ht)
{
foreach (string ss in v.Value.ToString().Split('.'))
{
s.Add(ss);
}
}