3

I am writing a C# program containing these lines:

Console.Writeline("1");  
Console.Writeline("2");  
[...]  
Console.Writeline("26");

Is there a quick way to type the 26 numbers? I'm using Visual Studio and Notepad++ for editors, but suggestions which use others editors are also welcome.

3
  • You have written Console.Writeline("1)"; or Console.Writeline("1"); ?
    – kokbira
    Apr 23, 2011 at 13:24
  • 1
    Have you considered writing a for loop?
    – Daniel Beck
    Apr 23, 2011 at 13:50
  • Some text editors can do this for you. In Notepad++, I can't check right now (using Linux), but I'd be surprised if you can't. You can certainly record and playback macros - if you can't insert the numbers where you want them, you can insert them somewhere else then use a macro to cut/paste them into place.
    – user31438
    Apr 24, 2011 at 8:07

3 Answers 3

3

well, it depends what softwares you have.

with Excel/Calc, you can do that:

  1. In A1 put: Console.Writeline("
  2. In B1 put: 1
  3. In C1 put: ");
  4. In D1 put: =concatenate(A1;B1;C1)
  5. Select from A1 to D1 and copy and paste to te first 26 rows
  6. Select from D1 to D26, copy and paste cells to your code

with windows batch:

  1. open cmd (start>execute>cmd)
  2. write that in cmd and press enter: for /l %i in (1,1,26) do echo.Console.Writeline("%i");>>code.txt
  3. write that in cmd and then copy to your code: notepad code.txt
  4. write that in cmd to delete created .txt: del code.txt
3

vim;

vim myfile
# Navigate to where you want the code. (Use hjkl to move)
i  # Enter insert mode
Console.Writeline("1")
esc # Enter command mode
qa # "start recording in register a"
# Duplicate the first line
yy
p

You should now see something like;

Console.Writeline("1")
Console.Writeline("1")
~
~
~
~
~
recording

Now place cursor at the 1 in the second line

Control a #increments the number
q #stop recording

Repeat the macro for as many lines as you want (in your case, 24 more times)

24@a
1
  • the vim way, hahahahah :)
    – kokbira
    Apr 25, 2011 at 2:01
2

This C# code snippet will print out source code for you to copy and paste into your program:

for (int i = 1; i < 27; i++) {
    Console.Writeline("Console.Writeline(\"" + i.ToString() + "\");");
}

I really hope this is just a badly reduced sample of what you actually want to do.

2
  • I admit that the example is a bit goofy; I was just trying to illustrate the general problem.
    – user12816
    Apr 23, 2011 at 16:45
  • 1
    well, you can create a simple sequencegenerator.exe, giving what you want as parameters, like: sequencegenerator.exe p1=Console.Writeline(\" p2=[1-27] p3="); tp1=text tp2=counter tp3=text (think that you can use it in future)
    – kokbira
    Apr 29, 2011 at 6:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.