我们最近收到了一些带有制表符分隔符的文件。我应该如何在VS中使用以下代码?
我们在导入sql server数据库时遇到了困难。
发送文件的供应商还发送了下面的代码供我们用于将文件从标签转换为逗号分隔符。
如何在visual studio中使用此文件。
我已经使用过几次视觉工作室,但我没有用过这样的单个文件。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace TabToComma
{
class Program
{
static void Main(string[] args)
{
StreamReader sr;
StreamWriter sw;
sr = new StreamReader(@"c:\input.txt");
sw = new StreamWriter(@"c:\output.txt");
string nextline;
string replacedline;
while (sr.Peek() >= 0)
{
nextline = sr.ReadLine();
replacedline = nextline.Replace('\t',','); // replace each tab in line with a comma
sw.WriteLine(replacedline);
}
sr.Close();
sw.Close();
}
}
}
或者,如果有人知道我可以用vbscript完成同样的事情,请指点我正确的方向。
非常感谢提前
你的文件有多大? – Ryan 2012-03-20 19:20:10
个人而言,我建议使用SSIS作业将文件导入数据库。 – 2012-03-20 19:20:32
为什么不使用文本编辑器并做一个简单的查找和替换? – 2012-03-20 19:20:38