C# 使用Regexp获取KeyValuePair中的信息
请帮助我分析此消息:C# 使用Regexp获取KeyValuePair中的信息,c#,regex,C#,Regex,请帮助我分析此消息: text=&direction=re&orfo=rus&files_id=&message=48l16qL2&old_charset=utf-8&template_id=&HTMLMessage=1&draft_msg=&re_msg=&fwd_msg=&RealName=0&To=john+%3Cjohn11%40gmail.com%3E&CC=&BCC=&am
text=&direction=re&orfo=rus&files_id=&message=48l16qL2&old_charset=utf-8&template_id=&HTMLMessage=1&draft_msg=&re_msg=&fwd_msg=&RealName=0&To=john+%3Cjohn11%40gmail.com%3E&CC=&BCC=&Subject=TestSubject&Body=%3Cp%3EHello+%D0%9F%D1%80%D0%B8%D0%B2%D0%B5%D1%82+%D1%82%D0%B5%D0%BA%D1%81%D1%82%3Cbr%3E%3Cbr%3E%3C%2Fp%3E&secur
我想获取KeyValuePair中的信息:键值
文本-
方向-re
等等。
如何转换:
Hello+%D0%9F%D1%80%D0%B8%D0%B2%D0%B5%D1%82+%D1%82%D0%B5%D0%BA%D1%81%…
有西里尔字母。谢谢。如果您想使用正则表达式,可以这样做:
// I only added the first 3 keys, but the others are basically the same
Regex r = new Regex(@"text=(?<text>.*)&direction=(?<direction>.*)&orfo=(?<orfo>.*)");
Match m = r.Match(inputText);
if(m.Success)
{
var text = m.Groups["text"].Value; // result is ""
var direction = m.Groups["direction"].Value; // re
var orfo = m.Groups["orfo"].Value;
}
如果要使用正则表达式,可以这样做:
// I only added the first 3 keys, but the others are basically the same
Regex r = new Regex(@"text=(?<text>.*)&direction=(?<direction>.*)&orfo=(?<orfo>.*)");
Match m = r.Match(inputText);
if(m.Success)
{
var text = m.Groups["text"].Value; // result is ""
var direction = m.Groups["direction"].Value; // re
var orfo = m.Groups["orfo"].Value;
}
看起来您正在处理一个URI,最好使用适当的类,而不是尝试找出详细的处理过程
看起来您正在处理一个URI,最好使用适当的类,而不是尝试找出详细的处理过程
这似乎是您第一次遇到查询字符串和URL编码字符。好消息是:你不需要正则表达式来解析它。博尔特:你建议使用Split吗?@Irima:use这似乎是你第一次遇到查询字符串和URL编码字符。好消息:你不需要正则表达式来解析这个。博尔特:你建议使用Split吗?@Irima:use