将229字符“23442006144600974201”(删除第3—8字符“442006”,增加第19 字符(“0”),即转变为224字符“231446009742001”。
文件比较大需要按229位数循环分割后再以以上规则替换~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~问的太简单,不要骂我~!!!
文件比较大需要按229位数循环分割后再以以上规则替换~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~问的太简单,不要骂我~!!!
解决方案 »
- 博客留言板中博主的ID用SQL语句怎么取?VS2008 C#
- dll被更换后,还需要重新编译应用程序吗?
- 关于水晶报表的问题
- 正则表达式问题,取出QP编码的内容
- C# VS VB.net -- 一定要选择C#
- ComboBox绑定空白值查询的困惑
- VS2008这个项目怎么打开
- 请问:Microsoft.DirectX ,Microsoft.DirectX.DirectPlay,Microsoft.DirectX.DirectSound 等这些Dll在哪里找啊?
- 菜鸟问题!!
- 关于 the page includes script from unauthenticated sources 的问题
- vs2003web项目迁移到2005, 一大堆"当前上下文中不存在名称"
- Remoting 客户端异常关闭问题,请教高手!!!!!!!!
一个txt文件中有很多字符,它们按229位来划分。就是说每229位字符表示一条数据。
首先需要把txt文件中的数据 按229位来划分位 n条数据
再对每条数据进行
将229字符“23442006144600974201”(删除第3—8字符“442006”,增加第19 字符(“0”),即转变为224字符“231446009742001” 的处理然后再把处理后的数据合并生成一个全是224位规则的txt数据文件。
1。截取前229位和其余的,用String.substring方法即可
对前229位进行你要的操作,依旧可用String.substring(),增加第19 字符(“0”),可以用之前的substring(),也可以直接插入,我记得是InsertAt方法,把处理后的字符保存到一个变量
2。对剩余的数据做上述操作,然后继续把处理后的累加到之前保存处理后数据的变量
3。循环结束后,把保存新数据的变量一次ReadToEnd全部写入TXT
试试全读出来
然后
"数据"=Regex.Replace("123.txt的内容",@".{229}",delegate(Match m){Return m.Value.SubString(0,2)+m.Value.SubString(8,10)+"0"+m.Value.SubString(19);})
string path = @"D:\1.txt";//原始txt路径
string path2 = @"D:\2.txt";//目标txt路径
int slen = 29;
StreamReader sr = new StreamReader(path, Encoding.Default);
string tmp = sr.ReadToEnd();//原始内容
string result = string.Empty;//需要的内容
//Response.Write(tmp + "<br");
// Response.Write("***********************************************************" + "<br");
sr.Close();
int scount = tmp.Length / slen;
string[] slist = new string[scount + 1];
for (int i = 0; i < slist.Length; i++)
{
if (i == slist.Length - 1)//最后一条数据,自己再加判断注意处理异常
{
slist[i] = tmp.Substring(i * slen);
slist[i] = slist[i].Insert(18, "0");
slist[i] = slist[i].Remove(2, 6);
result += slist[i];
//Response.Write(slist[i] + "<br");
}
else
{
slist[i] = tmp.Substring(i * slen, slen);
slist[i] = slist[i].Insert(18, "0");
slist[i] = slist[i].Remove(2, 6);
result += slist[i];
//Response.Write(slist[i] + "<br");
}
}
StreamWriter sw = new StreamWriter(path2, false);
sw.Write(result);
sw.Close();
------->
int slen = 229;//229位字符表示一条数据,按长度截取
算法应该可以再优化下~