Community
    • Login

    Template substitution from list

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    templatessubstitution
    2 Posts 2 Posters 385 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Atanvarno AldarionA Offline
      Atanvarno Aldarion
      last edited by

      Hey, I have to define lots of identical structures for many variables.
      Is there some plug-in for N++ that would allow me to have:

      1. A list of names:

      HARRY
      RON
      HERMIONE
      …

      1. A template like:

      STUDENT [NAME] IS:
      NAME: [NAME]
      ID: 1-[NAME]-2
      BIOGRAPHY: [NAME]'s biography follows.

      and would let me combine them into:

      STUDENT HARRY IS:
      NAME: HARRY
      ID: 1-HARRY-2
      BIOGRAPHY: HARRY’s biography follows.

      STUDENT RON IS:
      NAME: RON
      ID: 1-RON-2
      BIOGRAPHY: RON’s biography follows.

      STUDENT HERMIONE IS:
      NAME: HERMIONE
      ID: 1-HERMIONE-2
      BIOGRAPHY: HERMIONE’s biography follows.

      Can something do that for me? Thanks :)

      EkopalypseE 1 Reply Last reply Reply Quote 0
      • EkopalypseE Offline
        Ekopalypse @Atanvarno Aldarion
        last edited by

        @Atanvarno-Aldarion

        Yes, there is, and it’s called the PythonScript plugin.
        Probably any other scripting plugin can do this too.

        Here is an example of what it might look like.

        names = [
        'HARRY',
        'RON',
        'HERMIONE',
        ]
        
        template = '''
        STUDENT {0} IS:
        NAME: {0}
        ID: 1-{0}-2
        BIOGRAPHY: {0}'s biography follows.
        '''
        
        editor.appendText('\r\n'.join([template.format(x) for x in names]))
        1 Reply Last reply Reply Quote 4

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        • First post
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors