如: {FileTransmission.exe|2009/12/23 15:02:05}{FileTransmission.vshost.exe|2009/12/23 15:02:00}{SQLbackup.exe|2009/12/25 16:13:48}{SQLbackup.vshost.exe|2009/12/25 16:30:12}{7z.dll|2009/12/24 23:02:00}{SevenZipSharp.dll|2009/12/24 23:02:00}
转换为Hashtable。
Hashtable 主键为 | 前面的 值为 | 后面的时间
本人很鹾,不会写,会的帮个忙。谢谢
7 个解决方案
#1
鹾?
#2
输入法太快了, 很笨的意思。。。
#3
这是很简单的分解字符串嘛...另外Hashtable过时了,能不用就别用...
string s = "{FileTransmission.exe|2009/12/23 15:02:05}{FileTransmission.vshost.exe|2009/12/23 15:02:00}{SQLbackup.exe|2009/12/25 16:13:48}{SQLbackup.vshost.exe|2009/12/25 16:30:12}{7z.dll|2009/12/24 23:02:00}{SevenZipSharp.dll|2009/12/24 23:02:00}";
var r = s.Split(new char[] { '}', '{' }, StringSplitOptions.RemoveEmptyEntries);
Dictionary<string, string> d = new Dictionary<string, string>();
foreach (var item in r)
{
var i = item.Split(new char[] { '|' });
d.Add(i[0], i[1]);
}
#4
没有考虑异常,自己加...
#5
Hashtable tab = new Hashtable();
string Text = "{FileTransmission.exe|2009/12/23 15:02:05}{FileTransmission.vshost.exe|2009/12/23 15:02:00}{SQLbackup.exe|2009/12/25 16:13:48}{SQLbackup.vshost.exe|2009/12/25 16:30:12}{7z.dll|2009/12/24 23:02:00}{SevenZipSharp.dll|2009/12/24 23:02:00}";
MatchCollection M = Regex.Matches( Text , @"\{(.*?)\}" );
string[] Temp;
foreach(Match N in M)
{
Temp = N.Groups[1].Value.Split('|');
tab[Temp[0]] = Temp[1];
}
#6
string s = ";
string[] arr = s.Split(new char[] { '}', '{' }, StringSplitOptions.RemoveEmptyEntries);
Hashtable ht= new Hashtable();
foreach (string s in arr)
{
strin[] arr2= s.Split(new char[] { '|' },StringSplitOptions.RemoveEmptyEntries);
ht.Add(arr2[0],arr2[1]);
}
string[] arr = s.Split(new char[] { '}', '{' }, StringSplitOptions.RemoveEmptyEntries);
Hashtable ht= new Hashtable();
foreach (string s in arr)
{
strin[] arr2= s.Split(new char[] { '|' },StringSplitOptions.RemoveEmptyEntries);
ht.Add(arr2[0],arr2[1]);
}
#7
谢谢。一晚上了早点休息吧
#1
鹾?
#2
输入法太快了, 很笨的意思。。。
#3
这是很简单的分解字符串嘛...另外Hashtable过时了,能不用就别用...
string s = "{FileTransmission.exe|2009/12/23 15:02:05}{FileTransmission.vshost.exe|2009/12/23 15:02:00}{SQLbackup.exe|2009/12/25 16:13:48}{SQLbackup.vshost.exe|2009/12/25 16:30:12}{7z.dll|2009/12/24 23:02:00}{SevenZipSharp.dll|2009/12/24 23:02:00}";
var r = s.Split(new char[] { '}', '{' }, StringSplitOptions.RemoveEmptyEntries);
Dictionary<string, string> d = new Dictionary<string, string>();
foreach (var item in r)
{
var i = item.Split(new char[] { '|' });
d.Add(i[0], i[1]);
}
#4
没有考虑异常,自己加...
#5
Hashtable tab = new Hashtable();
string Text = "{FileTransmission.exe|2009/12/23 15:02:05}{FileTransmission.vshost.exe|2009/12/23 15:02:00}{SQLbackup.exe|2009/12/25 16:13:48}{SQLbackup.vshost.exe|2009/12/25 16:30:12}{7z.dll|2009/12/24 23:02:00}{SevenZipSharp.dll|2009/12/24 23:02:00}";
MatchCollection M = Regex.Matches( Text , @"\{(.*?)\}" );
string[] Temp;
foreach(Match N in M)
{
Temp = N.Groups[1].Value.Split('|');
tab[Temp[0]] = Temp[1];
}
#6
string s = ";
string[] arr = s.Split(new char[] { '}', '{' }, StringSplitOptions.RemoveEmptyEntries);
Hashtable ht= new Hashtable();
foreach (string s in arr)
{
strin[] arr2= s.Split(new char[] { '|' },StringSplitOptions.RemoveEmptyEntries);
ht.Add(arr2[0],arr2[1]);
}
string[] arr = s.Split(new char[] { '}', '{' }, StringSplitOptions.RemoveEmptyEntries);
Hashtable ht= new Hashtable();
foreach (string s in arr)
{
strin[] arr2= s.Split(new char[] { '|' },StringSplitOptions.RemoveEmptyEntries);
ht.Add(arr2[0],arr2[1]);
}
#7
谢谢。一晚上了早点休息吧