我們最近收到了一些帶有製表符分隔符的文件。我應該如何在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