用正则表达式匹配,然后用SubString var rg = new Regex("你的Pattern"); var match = rg.Match("你的文本"); var matchText = match.Group[0].Value; //你找到的字符串 var lastTen = matchText.Substring(matchText.Length - 10); 结束。
str的内容怎样从文本里得来呢,要知道我的文本几十兆大小的
Regex reg=new Regex("查找的条件(?<str>.{10})"); MatchCollection mac=reg.matches(文本); foreach(match m in mac) { console.write(m.groups["str"].value); }
FileStream fs = File.OpenRead("你的文件"); if (fs.Length < 10) { fs.Close(); return; } fs.Seek(-10, SeekOrigin.End); byte[] buf = new byte[10]; fs.Read(buf, 0, 10); //Encoding.GetEncoding("gb2312")根据你实际的修改 string result = Encoding.GetEncoding("gb2312").GetString(buf);//result就是你要的 fs.Close();
string txt=文本;string reslute=txt.substring(txt.insideof(str),10);
console.write(reslute);
var rg = new Regex("你的Pattern");
var match = rg.Match("你的文本");
var matchText = match.Group[0].Value; //你找到的字符串
var lastTen = matchText.Substring(matchText.Length - 10);
结束。
MatchCollection mac=reg.matches(文本);
foreach(match m in mac)
{
console.write(m.groups["str"].value);
}
if (fs.Length < 10)
{
fs.Close();
return;
}
fs.Seek(-10, SeekOrigin.End);
byte[] buf = new byte[10];
fs.Read(buf, 0, 10);
//Encoding.GetEncoding("gb2312")根据你实际的修改
string result = Encoding.GetEncoding("gb2312").GetString(buf);//result就是你要的
fs.Close();