紧急求救.......

ledaowutuobang 2012-08-01 09:10:36
309019,fhn4guxnj3baupp401o5awfg,/search/?keyword=名品打折网,,2012-07-02 10:16:38.580,2012/7/2,GET,0,61.49.0.229,Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; GTB6.4; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; CIBA; SE 2.X MetaSr 1.0)

求教高师指点,怎么样把名品打折网取出来 放在一个文件中,就是读一个多行类似的代码,然后把=和,之间的东西取出来放到一个文档中!
...全文
134 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
dragonAhao 2012-08-03
  • 打赏
  • 举报
回复
先来个字符串分割split(“,”),再来个取得第二对象,再来个字符串截取  substring()好了结果出现
hfdsoft 2012-08-02
  • 打赏
  • 举报
回复

/// <summary>
/// 读取文本文件内容
/// </summary>
/// <param name="filePath">文件路径绝对路径,如 C:\1.txt</param>
/// <returns></returns>
public static string ReadTextFile(string filePath)
{
string strFileContent = "";
if (File.Exists(filePath))
{
strFileContent = File.ReadAllText(filePath);
}
return strFileContent;
}

/// <summary>
/// 将文件内容存入filePath指定文件,替换原有内容,若文件不存在,则新建文件
/// </summary>
/// <param name="filePath">文件绝对路径</param>
/// <param name="content">文件内容</param>
/// <returns></returns>
public static bool ModifyFile(string filePath, string content)
{
if (File.Exists(filePath))
{
File.Delete(filePath);
}
using (FileStream fs = File.Create(filePath))
{
Byte[] file = new UTF8Encoding(true).GetBytes(content);
fs.Write(file, 0, file.Length);
}
return File.Exists(filePath);
}
ledaowutuobang 2012-08-02
  • 打赏
  • 举报
回复
没有哪位大侠可以帮我吗?
ledaowutuobang 2012-08-01
  • 打赏
  • 举报
回复
他是一个文件,里面有很多的数据都是这样的格式,也就是说需要读取这个文件然后在写一个文件出来就OK了!大侠麻烦了....[Quote=引用 5 楼 的回复:]

C# code

string source =
"309019,fhn4guxnj3baupp401o5awfg,/search/?keyword=名品打折网,,2012-07-02 10:16:38.580,2012/7/2,GET,0,61.49.0.229,Mozilla/4.0 (compatible; MSIE 6.0; Wi……
[/Quote]
hfdsoft 2012-08-01
  • 打赏
  • 举报
回复

string source =
"309019,fhn4guxnj3baupp401o5awfg,/search/?keyword=名品打折网,,2012-07-02 10:16:38.580,2012/7/2,GET,0,61.49.0.229,Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; GTB6.4; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; CIBA; SE 2.X MetaSr 1.0)";
string Pattern = "keyword=([^,]+)";
var result = Regex.Match(source, Pattern).ToString().Replace("keyword=","");
ledaowutuobang 2012-08-01
  • 打赏
  • 举报
回复
大侠能否写出代码?[Quote=引用 3 楼 的回复:]

正则

keyword=([^,]+)
[/Quote]
hfdsoft 2012-08-01
  • 打赏
  • 举报
回复
正则

keyword=([^,]+)
ledaowutuobang 2012-08-01
  • 打赏
  • 举报
回复
该红的的字符前只有一个=,大侠能否给出代码?
christ 2012-08-01
  • 打赏
  • 举报
回复
string str = "/?keyword=名品打折网,,2012-07-02 10:16:38"
如果只有一个=号或者这个=号一定是第一个出现的=号的话
先得到“=”的位置
int index= str.indexof('=')
前面可能有=号的话 看能不能用 indexof("keyword=")
将=号前面的字符去掉 str=str.SubString(index+1)
再得到第一个“,”的位置 消掉该位置以后的字符
str=str.Remove(str.IndexOf(',')) 即可得到 “名品打折网”

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧