我怎样才能读取字符串值
QuoteNo:32586 / CustomerNo:ABCDEF /总金额:32 /加工:否
我想以任何顺序读取字符串的值
答案 0 :(得分:3)
答案 1 :(得分:3)
不确定您要做什么,但是根据您给定的字符串,它可能是以下
string input = "QuoteNo:32586/CustomerNo:ABCDEF/TotalAmount:32/Processed:No";
var query = from pair in input.Split('/')
let items = pair.Split(':')
select new
{
Part = items[0],
Value = items[1]
};
// turn into list and access by index
var list = query.ToList();
// or turn into dictionary and access by key
Dictionary<string, string> dictionary
= query.ToDictionary(item => item.Part, item => item.Value);
答案 2 :(得分:0)
我全都是针对neebie的问题,但我假设有一定程度的google-ability
http://www.daniweb.com/forums/thread60361.html
http://www.dreamincode.net/forums/topic/12793-c%23-reading-each-character-of-a-string/
https://web.archive.org/web/1/http://articles.techrepublic%2ecom%2ecom/5100-10878_11-6030362.html
答案 3 :(得分:0)
string str = "QuoteNo:32586/CustomerNo:ABCDEF/TotalAmount:32/Processed:No";
string split = str.Split('/');
foreach(string s in split)
{
int index = s.IndexOf(':');
if (index <= 0 || index + 1 >= str.Length) throw new Exception();
string name = s.SubString(0,index);
string value = s.SubString(index+1);
}