1

大家好,我是初级 SQL 开发人员。我有一个文本文件,其中包含 1100 行搜索结果,每行包含一个文件路径和与该文件关联的存储过程。每一行都有如下结构:

abc\def\ghi\***.cs(40): jkl=******.*****.******, "proc_pqrst", parms);

abc\def\ghi\***.cs文件的文件路径在哪里***.cs。存储过程名称以 . 开头proc_。我必须提取***.cs和相应的存储过程名称proc_开头并将它们写入 .xls 文件。有人可以帮助我编写解析程序来做到这一点吗?我还可以获得关于我应该在哪里编写 c# 代码以及应该在哪里编译它的详细大纲吗?这可能是一个很大的帮助,因为我没有任何 C# 知识。

谢谢你,BK。

4

4 回答 4

2

这可能听起来很傻,但更好的选择可能是将原始 CSV 导入 Excel,然后编写一个宏来进行提取。可能是比 C#、Visual Studio 等更温和的学习曲线。

于 2010-04-22T21:21:44.033 回答
1

至于解析,你可以使用正则表达式,比如这个:

^(.*?\.cs).*"(proc_[A-Za-z0-9]*?)".*$

(顺便说一句,我没有测试过,所以它可能不起作用)

在导出到 XLS 文件方面,这有点困难。如果你打算在安装了 Excel 的 Windows 机器上运行它,那么我相信你可以使用 COM 让 Excel 为你做这件事,但否则,你必须: 1. 实现 XLS 文件格式(困难),2. 购买 XLS 文件格式的实现(昂贵),或 3. 做其他事情,例如自动化 OpenOffice 或其他事情。

于 2010-04-22T21:24:18.387 回答
1

If you absolutely need an xls file (instead of just csv), the FileHelpers library makes it easy to write an xls file.

FileHelpers takes a strongly typed class and writes it as a csv or xls, or can connect directly to a SQL server and save records there.

Basically, you'd have something like:

public class Record {
    public string filename;
    public string storedProc;
}

You could use Robert Harvey's code or a regex to extract the path and procedure names, create a new Record, and drop them in the new object.

Record r = new Record();
r.filename = myString.Substring(0, myString.IndexOf(".cs"),3);       
r.storedProc= myString.Substring(myString.IndexOf("proc_")).Substring(0, temp.IndexOf('\"'));       

You can then use the ExcelStorage class to save the file.

于 2010-04-23T01:16:46.690 回答
0
// returns abc\def\ghi\something.cs
string path = myString.Substring(0, myString.IndexOf(".cs"),3);

string temp = myString.Substring(myString.IndexOf("proc_"));

// returns proc_pqrst
string proc = temp.Substring(0, temp.IndexOf('\"')));

要创建在 Excel 中可读的文件,只需写出一个逗号分隔的文件 (CSV)。

于 2010-04-22T21:30:45.357 回答