how to put numbers every two rows?



  • i have this,

            break;
            case("3"):
            thisLayer.font = font;
            break;
            case("4"):
            thisLayer.font = font;
            break;
            case("5"):
            thisLayer.font = font;
            break;
            case("6"):
            thisLayer.font = font;
            break;
            case("7"):
            thisLayer.font = font;
            break;
            case("8"):
            thisLayer.font = font;
            break;
            case("9"):
            thisLayer.font = font;
            break;
            case("10"):
            thisLayer.font = font;
    

    Should be like this

            break;
            case("3"):
            thisLayer.font = font3;
            break;
            case("4"):
            thisLayer.font = font4;
            break;
            case("5"):
            thisLayer.font = font5;
            break;
            case("6"):
            thisLayer.font = font6;
            break;
            case("7"):
            thisLayer.font = font7;
            break;
            case("8"):
            thisLayer.font = font8;
            break;
            case("9"):
            thisLayer.font = font9;
            break;
            case("10"):
            thisLayer.font = font10;
    

    Also

    i have this

    					"label" : "1",
    					"value" : "1"
    				},
    				{
    					"label" : "2",
    					"value" : "2"
    				},
    				{
    					"label" : "3",
    					"value" : "3"
    				},
    				{
    					"label" : "4",
    					"value" : "4"
    				},
    				{
    					"label" : "5",
    					"value" : "5"
    

    but it must be up to 708. I can copy text up to 708, but i have to change numbers from 1 to 708 manually -_-.

    i found this theme, but this command doesn’t works “(?<=\w)\R” with my first problem. What to do with the second problem, i have no idea.



  • @DimakSerpg

    You might try this for the first problem:

    find: case\("(\d+)"\):\R\h+thisLayer\.font\h=\hfont\K
    repl: ${1}

    What to do with the second problem, i have no idea.

    To get you started, look into the Column editor feature; press Alt+c, and experiment with the Number to Insert part. Then you can use some regex replacements to add in the other text around your numbers.



  • Hi @DimakSerpg

    Concerning your first issue, I would resolve it by means of the following regex:

    Search: (?<=case\(")(\d+)("\):\R[^;]+)\K
    Replace: $0$1
    

    Put the caret at the very beginning of the document, select just the Regular Expression mode and click on Replace All.

    Take care and have fun!

    @Alan-Kilborn beat me, even quite similar regex :)

    PS: Concerning the second issue, though there are ways to accomplish this within Notepad++, I would prefer to script it. It’s very easy.



  • It worked, thanks



  • @astrosofista i have zero knowledge in scripting :)



  • Of course i can do something like this, but how to delete numbers between rows?

    				{                  1
    					"label" : "1",
    					"value" : "1"
    				},                 1
    				{                  2
    					"label" : "2",
    					"value" : "2"
    				},                 2
    				{                  3
    					"label" : "3",
    					"value" : "3"
    				},                 3
    				{                  4
    					"label" : "4",
    					"value" : "4"
    				},                 4
    				{                  5
    					"label" : "5",
    					"value" : "5"
    				},                 5
    				{                  6
    					"label" : "6",
    					"value" : "6"
    				},                 6
    				{                  7
    					"label" : "7",
    					"value" : "7"
    				},                 7
    				{                  8
    					"label" : "8",
    					"value" : "8"
    				},                 8
    				{                  9
    					"label" : "9",
    					"value" : "9"
    				},                 9
    				{                  10
    					"label" : "10",
    					"value" : "10"
    				},                 10


  • @DimakSerpg

    Good try! To delete the unwanted numbers, try this new regex

    Search: (?-s)\{\K.*$|\},\K.*$
    Replace: [leave empty]
    

    Put the caret at the very beginning of the document, select just the Regular Expression mode and click on Replace All.

    Have fun!



  • @astrosofista oh nice, thank you man!



  • @DimakSerpg

    Of course i can do something like this, but how to delete numbers between rows?

    That wasn’t quite the approach I was thinking of with the column editor number insertion stuff. :-)



  • @Alan-Kilborn was your method easier or more difficult? :)



  • @DimakSerpg

    So my method would have been to generate the number list in an empty file, e.g. :

    1
    2
    3
    4
    5
    etc
    708
    

    and then use regex replacement to build the extra text around that.

    but…it seems that you got where you needed to go…so that’s good!



  • Hi @DimakSerpg, All

    If the problems you posted here are common in your daily workload, then I would suggest you to learn scripting.

    Just for the record, the script I spoke about. This demo is in AutoHotkey, but it could be scripted in several other languages. All the text is automatically created and the outcome is placed on the clipboard, ready to be pasted.

    Output  := ""
    Num     := 3 ; replace "3" with the correct number -> 708
    Template = 
    (join`n
    				{
    					"{}" : "{}",
    					"{}" : "{}"
    				},
    
    )
    
    Loop, % Num {
    	Output .= Format("`t`t`t`t" Template, "label", A_Index, "value", A_Index)
    }
    
    MsgBox, % Clipboard := Output
    return
    

    Output:

    			{
    				"label" : "1",
    				"value" : "1"
    			},
    			{
    				"label" : "2",
    				"value" : "2"
    			},
    			{
    				"label" : "3",
    				"value" : "3"
    			},
    

    I hope this simple example will encourage you to learn scripting.



  • There is another easy solution without scripting: first you have to join the rows like this:

    {"label" : "1","value" : "1"	},
    {"label" : "2","value" : "2"	},
    {"label" : "3","value" : "3"	},
    

    or even better just create a line like this

    {"label" : "n","value" : "n"	},
    

    and than duplicate it as many times as you need

    {"label" : "","value" : ""	},
    {"label" : "","value" : ""	},
    {"label" : "","value" : ""	},
    {"label" : "","value" : ""	},
    {"label" : "","value" : ""	},
    {"label" : "","value" : ""	},
    

    Than use the column editor that you will find in Edit menu, to add numbers as you want after label and after value.

    {"label" : "1","value" : "1"	},
    {"label" : "2","value" : "2"	},
    {"label" : "3","value" : "3"	},
    {"label" : "4","value" : "4"	},
    {"label" : "5","value" : "5"	},
    {"label" : "6","value" : "6"	},
    ...
    

    Maybe you can even find a plugin to format back the whole code with new lines and indentations with just two clicks : I think JSTool will make the trick.

    Or alternatively you can use find and replace to put back the new lines and the indentations.
    Both ways will work.

    You can operate with both codes more or less the same way :

    case("1  "):         thisLayer.font = font1  ;         break;
    case("2  "):         thisLayer.font = font2  ;         break;
    case("3  "):         thisLayer.font = font3  ;         break;
    case("4  "):         thisLayer.font = font4  ;         break;
    case("5  "):         thisLayer.font = font5  ;         break;
    case("6  "):         thisLayer.font = font6  ;         break;
    case("7  "):         thisLayer.font = font7  ;         break;
    case("8  "):         thisLayer.font = font8  ;         break;
    case("9  "):         thisLayer.font = font9  ;         break;
    case("10 "):         thisLayer.font = font10 ;         break;
    case("11 "):         thisLayer.font = font11 ;         break;
    case("12 "):         thisLayer.font = font12 ;         break;
    case("13 "):         thisLayer.font = font13 ;         break;
    case("14 "):         thisLayer.font = font14 ;         break;
    case("15 "):         thisLayer.font = font15 ;         break;
    case("16 "):         thisLayer.font = font16 ;         break;
    case("17 "):         thisLayer.font = font17 ;         break;
    case("18 "):         thisLayer.font = font18 ;         break;
    case("19 "):         thisLayer.font = font19 ;         break;
    case("20 "):         thisLayer.font = font20 ;         break;
    case("21 "):         thisLayer.font = font21 ;         break;
    case("22 "):         thisLayer.font = font22 ;         break;
    case("23 "):         thisLayer.font = font23 ;         break;
    case("24 "):         thisLayer.font = font24 ;         break;
    case("25 "):         thisLayer.font = font25 ;         break;
    case("26 "):         thisLayer.font = font26 ;         break;
    case("27 "):         thisLayer.font = font27 ;         break;
    case("28 "):         thisLayer.font = font28 ;         break;
    case("29 "):         thisLayer.font = font29 ;         break;
    case("30 "):         thisLayer.font = font30 ;         break;
    case("31 "):         thisLayer.font = font31 ;         break;
    case("32 "):         thisLayer.font = font32 ;         break;
    case("33 "):         thisLayer.font = font33 ;         break;
    case("34 "):         thisLayer.font = font34 ;         break;
    case("35 "):         thisLayer.font = font35 ;         break;
    case("36 "):         thisLayer.font = font36 ;         break;
    case("37 "):         thisLayer.font = font37 ;         break;
    case("38 "):         thisLayer.font = font38 ;         break;
    case("39 "):         thisLayer.font = font39 ;         break;
    case("40 "):         thisLayer.font = font40 ;         break;
    case("41 "):         thisLayer.font = font41 ;         break;
    case("42 "):         thisLayer.font = font42 ;         break;
    case("43 "):         thisLayer.font = font43 ;         break;
    

    with find and replace you can remove the space after the numbers:

    case("1"):         thisLayer.font = font1  ;         break;
    case("2"):         thisLayer.font = font2  ;         break;
    case("3"):         thisLayer.font = font3  ;         break;
    case("4"):         thisLayer.font = font4  ;         break;
    case("5"):         thisLayer.font = font5  ;         break;
    case("6"):         thisLayer.font = font6  ;         break;
    case("7"):         thisLayer.font = font7  ;         break;
    case("8"):         thisLayer.font = font8  ;         break;
    case("9"):         thisLayer.font = font9  ;         break;
    case("10"):         thisLayer.font = font10 ;         break;
    case("11"):         thisLayer.font = font11 ;         break;
    case("12"):         thisLayer.font = font12 ;         break;
    case("13"):         thisLayer.font = font13 ;         break;
    case("14"):         thisLayer.font = font14 ;         break;
    case("15"):         thisLayer.font = font15 ;         break;
    case("16"):         thisLayer.font = font16 ;         break;
    case("17"):         thisLayer.font = font17 ;         break;
    case("18"):         thisLayer.font = font18 ;         break;
    case("19"):         thisLayer.font = font19 ;         break;
    case("20"):         thisLayer.font = font20 ;         break;
    case("21"):         thisLayer.font = font21 ;         break;
    case("22"):         thisLayer.font = font22 ;         break;
    case("23"):         thisLayer.font = font23 ;         break;
    case("24"):         thisLayer.font = font24 ;         break;
    case("25"):         thisLayer.font = font25 ;         break;
    case("26"):         thisLayer.font = font26 ;         break;
    case("27"):         thisLayer.font = font27 ;         break;
    case("28"):         thisLayer.font = font28 ;         break;
    case("29"):         thisLayer.font = font29 ;         break;
    case("30"):         thisLayer.font = font30 ;         break;
    case("31"):         thisLayer.font = font31 ;         break;
    case("32"):         thisLayer.font = font32 ;         break;
    case("33"):         thisLayer.font = font33 ;         break;
    case("34"):         thisLayer.font = font34 ;         break;
    case("35"):         thisLayer.font = font35 ;         break;
    case("36"):         thisLayer.font = font36 ;         break;
    case("37"):         thisLayer.font = font37 ;         break;
    case("38"):         thisLayer.font = font38 ;         break;
    case("39"):         thisLayer.font = font39 ;         break;
    
    

    Then you can format back the text with Plugins > JSTools > JSFormat

    {
    	"label": "789",
    	"value": "789"
    },
    {
    	"label": "790",
    	"value": "790"
    },
    {
    	"label": "791",
    	"value": "791"
    },
    {
    	"label": "792",
    	"value": "792"
    },
    
    case ("1"):
    	thisLayer.font = font1;
    	break;
    case ("2"):
    	thisLayer.font = font2;
    	break;
    case ("3"):
    	thisLayer.font = font3;
    	break;
    case ("4"):
    	thisLayer.font = font4;
    	break;
    case ("5"):
    	thisLayer.font = font5;
    	break;
    case ("6"):
    	thisLayer.font = font6;
    	break;
    case ("7"):
    	thisLayer.font = font7;
    	break;
    case ("8"):
    	thisLayer.font = font8;
    	break;
    case ("9"):
    	thisLayer.font = font9;
    	break;
    case ("10"):
    	thisLayer.font = font10;
    	break;
    

    You will get it done in about 30 seconds of job, but remember to recheck the code for mistakes in case you will correct them doing the procedure again or directly by hands. But I don’t think it will be necessary much more hand corrections.

    Enjoy



  • @wonkawilly

    Nice posting.
    That’s the kind of thing I had in mind earlier, but I didn’t elaborate all the details like you did because the OP indicated he already had a solution that worked.
    Thank you for filling in the gap I left open.



  • @Alan-Kilborn In my post there is a little error in the row:

    {"label" : "n","value" : "n"	},
    

    the following is the right one

    {"label" : "","value" : ""	},
    

    Explication:
    Remove the n before duplicating the row. Sorry I couldn’t correct in time directly into the original post because I had just 180 seconds to make corrections but I hadn’t enough time. Sorry again



  • @wonkawilly said in how to put numbers every two rows?:

    there is a little error in the row

    It’s OK. BTW I didn’t go step by step through to check for accuracy.
    It’s enough that you very clearly showed the technique, enough to get someone started down that same path.


Log in to reply