|1#24#8613602457789#1234567895#11-08-29 11:31:32
|2#24#8613602457789#我们是害虫#11-08-29 11:34:38
|3#24#8613602457789#我们是害虫#11-08-29 11:44:41
|4#24#8613602457789#我们是害虫#11-08-29 11:50:30如何能去掉不要的字符了,我只要手机号码和内容
|4#24#8613602457789#我们是害虫#11-08-29 11:50:30
假如这个字符,我要的是8613602457789 ,内容是我们是害虫,格式基本一样,那个高手帮忙写个截取的函数,感激不尽
|2#24#8613602457789#我们是害虫#11-08-29 11:34:38
|3#24#8613602457789#我们是害虫#11-08-29 11:44:41
|4#24#8613602457789#我们是害虫#11-08-29 11:50:30如何能去掉不要的字符了,我只要手机号码和内容
|4#24#8613602457789#我们是害虫#11-08-29 11:50:30
假如这个字符,我要的是8613602457789 ,内容是我们是害虫,格式基本一样,那个高手帮忙写个截取的函数,感激不尽
|2#24#8613602457789#我们是害虫#11-08-29 11:34:38
|3#24#8613602457789#我们是害虫#11-08-29 11:44:41
|4#24#8613602457789#我们是害虫#11-08-29 11:50:30";
Regex reg = new Regex(@"(?<=#)(\d{11,13})#([^#]+)(?=#)");
foreach (Match m in reg.Matches(str))
Console.WriteLine("{0} {1}", m.Groups[1].Value, m.Groups[2].Value);
//来个LINQ的
void Main()
{
String x = @"|1#24#8613602457789#1234567895#11-08-29 11:31:32
|2#24#8613602457789#我们是害虫#11-08-29 11:34:38
|3#24#8613602457789#我们是害虫#11-08-29 11:44:41
|4#24#8613602457789#我们是害虫#11-08-29 11:50:30";
var result=(from y in x.Split('\n')
from z in y.Split('#').Skip(2).Take(2)
select z).ToList();
result.ForEach(r=>Console.WriteLine(r));
/*
8613602457789
1234567895
8613602457789
我们是害虫
8613602457789
我们是害虫
8613602457789
我们是害虫
*/
}
|2#24#8613602457789#我们是害虫#11-08-29 11:34:38
|3#24#8613602457789#我们是害虫#11-08-29 11:44:41
|4#24#8613602457789#我们是害虫#11-08-29 11:50:30加入你的内容是从txt文档中逐行读取到的[code=C#]
//定义二个数组
ArrayList number = new ArrayList();
ArrayList content = new ArrayList();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string Path = Server.MapPath("info.txt");
getStr(Path); for (int i = 0; i < number.Count; i++)
{
Response.Write(number[i].ToString()+" | ");
}
Response.Write("<br/>");
for (int j = 0; j< content.Count; j++)
{
Response.Write(ip[j].ToString() + " | ");
}
}
}
//读取txt行中的每一个数据
public void getStr(string Path)
{
string strLine = "";
int i = 0;
try
{
StreamReader sr = new StreamReader(Path, Encoding.GetEncoding("GB2312"));
while ((strLine=sr.ReadLine()) != null)
{
string[] val = strLine.Split('#');
//将数据保存在ArrayList集合中
number.Add(val[2]);
content.Add(val[3]);
Response.Write("当前第"+i+"行:<br/>");
foreach (string s in val)
{
Response.Write(s + "<br>");
}
i++;
Response.Write("<hr>");
}
sr.Dispose();
sr.Close();
}
catch
{
}
}
//定义二个数组
ArrayList number = new ArrayList();
ArrayList content = new ArrayList();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string Path = Server.MapPath("info.txt");
getStr(Path); for (int i = 0; i < number.Count; i++)
{
Response.Write(number[i].ToString()+" | ");
}
Response.Write("<br/>");
for (int j = 0; j< content.Count; j++)
{
Response.Write(ip[j].ToString() + " | ");
}
}
}
//读取txt行中的每一个数据
public void getStr(string Path)
{
string strLine = "";
int i = 0;
try
{
StreamReader sr = new StreamReader(Path, Encoding.GetEncoding("GB2312"));
while ((strLine=sr.ReadLine()) != null)
{
string[] val = strLine.Split('#');
//将数据保存在ArrayList集合中
number.Add(val[2]);
content.Add(val[3]);
Response.Write("当前第"+i+"行:<br/>");
foreach (string s in val)
{
Response.Write(s + "<br>");
}
i++;
Response.Write("<hr>");
}
sr.Dispose();
sr.Close();
}
catch
{
}
}