简体   繁体   English

如何使用C#和/或Notepad ++在文本行的开头添加连续数字?

[英]How can I add consecutive numbers to the front of my lines of text using C# and/or Notepad++?

I basically have a whole list of data that looks like this: 我基本上有一个完整的数据列表,如下所示:

text', 0, 16, 0, 160),
text text', 0, 36, 0, 720),
text text text', 6, 14, 200, 400),
text text', 6, 20, 40, 185),
text text text text', 6, 6, 80, 80),
text text', 0, 18, 0, 260),
text text text', 3, 3, 60, 60),

I need this to look like this: 我需要这样看起来像这样:

(1444, text text', 0, 36, 0, 720),
(1445, text text text', 6, 14, 200, 400),
(1446, text text', 6, 20, 40, 185),
(1447, text text text text', 6, 6, 80, 80),
(1448, text text', 0, 18, 0, 260),
(1449, text text text', 3, 3, 60, 60),

So I basically wrote a for loop in C# to generate the numbers: 所以我基本上在C#中编写了一个for循环来生成数字:

 for(int i =0; i < amount; i ++)
        {
            Console.WriteLine("("+counter+",");
            counter++;
        }

Counter being the numbers I need and amount being the amount of times I need numbers generated. 计数器是我需要的数字,数量是我需要生成数字的次数。

I am trying to figure out how to get "(1111," in front of "text', 0, 0, 0, 0)," per each line, I was trying to find and replace in notepad but I couldn't get it to work, is there a way I could do the whole thing in C#? 我试图找出如何在每一行的“ text”,0、0、0、0)前面获取“(1111,”),我试图在记事本中查找和替换,但我无法获得它可以正常工作,有没有办法我可以用C#完成全部操作? Or any other way at all? 还是其他方式?

var indexedLines = yourData.Select((line, idx) => new {Line = line, Index = idx});

foreach(var indexedLine in indexedLines)
    Console.WriteLine("({0}, {1}", indexedLine.Index, indexedLine.Line);

您不能只使用Excel或其他电子表格处理器吗?

Yes, use the following resource: http://msdn.microsoft.com/en-us/library/ezwyzy7b.aspx 是的,请使用以下资源: http : //msdn.microsoft.com/zh-cn/library/ezwyzy7b.aspx

And try doing something like: 并尝试执行以下操作:

Console.Writeline("(" + counter + "," + line);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM