Community
    • Login

    Multiple choice questions need help

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    4 Posts 3 Posters 3.9k 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.
    • CTL SignupC
      CTL Signup
      last edited by CTL Signup

      Hello

      Trying to add numbers to the beginning of each questions, example

      What is the molecular unit of heredity?
      *a) Gene
      b) DNA
      c) Cromosomas
      d) Nucleotides1

      A gene is a locus or region of…
      *a) DNA
      b) Chromosomes
      c) Regulatory Regions
      d) RNA

      i would need it to be like this

      1 What is the molecular unit of heredity?
      *a) Gene
      b) DNA
      c) Cromosomas
      d) Nucleotides1

      2 A gene is a locus or region of…
      *a) DNA
      b) Chromosomes
      c) Regulatory Regions
      d) RNA

      trying to find an easy way to add numbers on select lines. We are talking hundreds of questions doing it manually is painful wondering if a feature in notepad++ can help with this.

      Thank you

      1 Reply Last reply Reply Quote 0
      • PeterJonesP
        PeterJones
        last edited by

        I don’t think NPP’s regular expressions will be able to help you directly – there’s no auto-increment on the search and replace, that I know of. Using a scripting language on the source text could work, but you’d have to either know the language, or be willing to learn it.

        Python is often mentioned on this forum, because of the excellent Python Script Plugin [Download here], which allows you live access to the contents of the files being edited by NPP [see the API documentation at Plugins > Python Script > Context-Help, after installing the plugin].

        If you don’t know or want to learn a scripting language, I might recommend reading your text file in word processor, and use the word processor’s auto-numbering features. (Actually, that’s possibly faster, even if you do already know Python.) A text editor can do many things, and one as powerful as NPP with its fleet of plugins can do quite a few “extras”, but it’s still not a word processor, and not intended to be.

        Another option, staying more in NPP: use a RegEx to mark up your text as Markdown, then use a Markdown processor to render it to a text (or text-like) format. In that case, I’d use two search/replace pairs, with regular expression selected:

        Search #1:      ^(\**[A-Za-z]+\))
        Replace #1:     \r\n    \1
        
        Search #2:      \R\R([A-Za-z])
        Replace #2:     \r\n\r\n1. \1
        

        If you don’t have a blank line before the first question, you’ll have to manually insert the "1. " before the first question.

        After you’ve got the Markdown version of your text, you can convert it to something else. You might be able to use @nea’s MarkdownViewer++; I haven’t tried it yet, but someday I will. Personally, I’ve used a custom filter for Preview HTML for a year or more, and been reasonably happy with it. (See my quick description of my setup in another thread, or a long version in a third thread). Using the Preview HTML, I can then select the rendered text, and paste it somewhere else, and it keeps the auto-numbering that Markdown bought for you.

        1 Reply Last reply Reply Quote 1
        • guy038G
          guy038
          last edited by guy038

          Hello, CTL Signup,

          As Peter Jones said, the N++ search/replace function isn’t able to auto-increment a number through multiple replacements.

          However, if we use a first regex S/R in order to display your “multiple choices” questions text in a particular form, we could use the N++ column editor to insert numbers. Then, a second regex S/R could get back the correct displaying of your text !

          Just one condition : we need an extra character not used, at all, in your text. I chose the Vertical Line character |, of Unicode code-point \x7C, but any other character may be used. Don’t forget to escape this character, in the search regex, with an anti-slash ( \ ) if this character is a special regex character, as for the | character !

          IMPORTANT : I also supposed that all lines, of the original text, begins at column 1 !


          So let’s go ! Starting with your original text, duplicated some times, below :

          What is the molecular unit of heredity?
          a) Gene
          b) DNA
          c) Cromosomas
          d) Nucleotides1
          
          A gene is a locus or region of…
          a) DNA
          b) Chromosomes
          c) Regulatory Regions
          d) RNA
          
          What is the molecular unit of heredity?
          a) Gene
          b) DNA
          c) Cromosomas
          d) Nucleotides1
          
          A gene is a locus or region of…
          a) DNA
          b) Chromosomes
          c) Regulatory Regions
          d) RNA
          What is the molecular unit of heredity?
          a) Gene
          b) DNA
          c) Cromosomas
          d) Nucleotides1
          
          A gene is a locus or region of…
          a) DNA
          b) Chromosomes
          c) Regulatory Regions
          d) RNA
          What is the molecular unit of heredity?
          a) Gene
          b) DNA
          c) Cromosomas
          d) Nucleotides1
          
          A gene is a locus or region of…
          a) DNA
          b) Chromosomes
          c) Regulatory Regions
          d) RNA
          What is the molecular unit of heredity?
          a) Gene
          b) DNA
          c) Cromosomas
          d) Nucleotides1
          
          A gene is a locus or region of…
          a) DNA
          b) Chromosomes
          c) Regulatory Regions
          d) RNA
          What is the molecular unit of heredity?
          a) Gene
          b) DNA
          c) Cromosomas
          d) Nucleotides1
          
          A gene is a locus or region of…
          a) DNA
          b) Chromosomes
          c) Regulatory Regions
          d) RNA
          What is the molecular unit of heredity?
          a) Gene
          b) DNA
          c) Cromosomas
          d) Nucleotides1
          
          A gene is a locus or region of…
          a) DNA
          b) Chromosomes
          c) Regulatory Regions
          d) RNA
          

          Using the regex S/R, below, with the Regular expression search mode checked :

          SEARCH (?-s)^\R|\R(\l\))|(.+)

          REPLACE (?1|\1)?2 \2 , with a space character before \2

          After clicking on the Replace All button, we obtain the modified text :

           What is the molecular unit of heredity?|a)  Gene|b)  DNA|c)  Cromosomas|d)  Nucleotides1
           A gene is a locus or region of…|a)  DNA|b)  Chromosomes|c)  Regulatory Regions|d)  RNA
           What is the molecular unit of heredity?|a)  Gene|b)  DNA|c)  Cromosomas|d)  Nucleotides1
           A gene is a locus or region of…|a)  DNA|b)  Chromosomes|c)  Regulatory Regions|d)  RNA
           What is the molecular unit of heredity?|a)  Gene|b)  DNA|c)  Cromosomas|d)  Nucleotides1
           A gene is a locus or region of…|a)  DNA|b)  Chromosomes|c)  Regulatory Regions|d)  RNA
           What is the molecular unit of heredity?|a)  Gene|b)  DNA|c)  Cromosomas|d)  Nucleotides1
           A gene is a locus or region of…|a)  DNA|b)  Chromosomes|c)  Regulatory Regions|d)  RNA
           What is the molecular unit of heredity?|a)  Gene|b)  DNA|c)  Cromosomas|d)  Nucleotides1
           A gene is a locus or region of…|a)  DNA|b)  Chromosomes|c)  Regulatory Regions|d)  RNA
           What is the molecular unit of heredity?|a)  Gene|b)  DNA|c)  Cromosomas|d)  Nucleotides1
           A gene is a locus or region of…|a)  DNA|b)  Chromosomes|c)  Regulatory Regions|d)  RNA
           What is the molecular unit of heredity?|a)  Gene|b)  DNA|c)  Cromosomas|d)  Nucleotides1
           A gene is a locus or region of…|a)  DNA|b)  Chromosomes|c)  Regulatory Regions|d)  RNA
          

          NOTES :

          This S/R does 3 exclusive actions :

          • It searches for pure blank lines ( ^\R ) and deletes them, during the replacement phase

          • It searches for the End of Line character(s), followed with a low-case letter then an ending round bracket ( \R(\l\)) ). In replacement, as group 1 ( the lowercase letter + the ) character ) exists, we rewrite it, preceded by an | character ( (?1|\1) )

          • Finally, it searches for all the contents of a no-blank line ( .+ ), if different from the first two cases ( that is to say the different qestions lines ! ) and rewrite them ( group 2 ), preceded with a space character ( ?2 \2 )

          The (?-s) syntax, at beginning, forces the regex engine to consider that the special dot character ( . ) matches a single standard character, only, even if you previously checked the . matches newline option


          Then :

          • Place the caret at the very beginning of the first line of this list, before the space character

          • Choose the menu option Edit > Column Editor… ( Alt + C )

          • Select the “radio button” option Number to Insert

          • Type 1 in the Initial number and Increased by fields

          • Leave the Repeat field empty and do not check the Leading zeros option

          • Select, if necessary, the Dec format of the numbers to insert

          • Finally, click on the OK button

          You should, now, get the following text :

          1  What is the molecular unit of heredity?|a)  Gene|b)  DNA|c)  Cromosomas|d)  Nucleotides1
          2  A gene is a locus or region of…|a)  DNA|b)  Chromosomes|c)  Regulatory Regions|d)  RNA
          3  What is the molecular unit of heredity?|a)  Gene|b)  DNA|c)  Cromosomas|d)  Nucleotides1
          4  A gene is a locus or region of…|a)  DNA|b)  Chromosomes|c)  Regulatory Regions|d)  RNA
          5  What is the molecular unit of heredity?|a)  Gene|b)  DNA|c)  Cromosomas|d)  Nucleotides1
          6  A gene is a locus or region of…|a)  DNA|b)  Chromosomes|c)  Regulatory Regions|d)  RNA
          7  What is the molecular unit of heredity?|a)  Gene|b)  DNA|c)  Cromosomas|d)  Nucleotides1
          8  A gene is a locus or region of…|a)  DNA|b)  Chromosomes|c)  Regulatory Regions|d)  RNA
          9  What is the molecular unit of heredity?|a)  Gene|b)  DNA|c)  Cromosomas|d)  Nucleotides1
          10 A gene is a locus or region of…|a)  DNA|b)  Chromosomes|c)  Regulatory Regions|d)  RNA
          11 What is the molecular unit of heredity?|a)  Gene|b)  DNA|c)  Cromosomas|d)  Nucleotides1
          12 A gene is a locus or region of…|a)  DNA|b)  Chromosomes|c)  Regulatory Regions|d)  RNA
          13 What is the molecular unit of heredity?|a)  Gene|b)  DNA|c)  Cromosomas|d)  Nucleotides1
          14 A gene is a locus or region of…|a)  DNA|b)  Chromosomes|c)  Regulatory Regions|d)  RNA
          15
          

          Using the second and final reges S/R, below, with the Regular expression search mode checked :

          SEARCH ^(\d)|\|

          REPLACE \r\n?1\1

          After clicking on the Replace All button, we obtain the expected text, with the numbered questions :-) Et voilà !

          1  What is the molecular unit of heredity?
          a)  Gene
          b)  DNA
          c)  Cromosomas
          d)  Nucleotides1
          
          2  A gene is a locus or region of…
          a)  DNA
          b)  Chromosomes
          c)  Regulatory Regions
          d)  RNA
          
          3  What is the molecular unit of heredity?
          a)  Gene
          b)  DNA
          c)  Cromosomas
          d)  Nucleotides1
          
          4  A gene is a locus or region of…
          a)  DNA
          b)  Chromosomes
          c)  Regulatory Regions
          d)  RNA
          
          5  What is the molecular unit of heredity?
          a)  Gene
          b)  DNA
          c)  Cromosomas
          d)  Nucleotides1
          
          6  A gene is a locus or region of…
          a)  DNA
          b)  Chromosomes
          c)  Regulatory Regions
          d)  RNA
          
          7  What is the molecular unit of heredity?
          a)  Gene
          b)  DNA
          c)  Cromosomas
          d)  Nucleotides1
          
          8  A gene is a locus or region of…
          a)  DNA
          b)  Chromosomes
          c)  Regulatory Regions
          d)  RNA
          
          9  What is the molecular unit of heredity?
          a)  Gene
          b)  DNA
          c)  Cromosomas
          d)  Nucleotides1
          
          10 A gene is a locus or region of…
          a)  DNA
          b)  Chromosomes
          c)  Regulatory Regions
          d)  RNA
          
          11 What is the molecular unit of heredity?
          a)  Gene
          b)  DNA
          c)  Cromosomas
          d)  Nucleotides1
          
          12 A gene is a locus or region of…
          a)  DNA
          b)  Chromosomes
          c)  Regulatory Regions
          d)  RNA
          
          13 What is the molecular unit of heredity?
          a)  Gene
          b)  DNA
          c)  Cromosomas
          d)  Nucleotides1
          
          14 A gene is a locus or region of…
          a)  DNA
          b)  Chromosomes
          c)  Regulatory Regions
          d)  RNA
          
          15
          

          NOTES :

          • The search S/R looks for, either

            • A digit, in column 1, at beginning of current line , stored as group 1 ( ^(\d) )

            • A | character ( \| )

          • In replacement, whatever the case, it, first, adds a line break ( \r\n)

          • Then if group 1 exists ( the first part of the alternative ) it rewrites the number


          Finally, you just have to delete the last line of this list, containing only a number

          Best Regards

          guy038

          1 Reply Last reply Reply Quote 1
          • PeterJonesP
            PeterJones
            last edited by

            @guy038 ,

            Although I frequently use the ALT+MouseSelect column editing, I had never looked in the Column Editor dialog box, and didn’t know it had the auto-number feature. I’ll have to keep that in mind. I love learning new-to-me features in NPP.

            And your regex mastery always astounds me. :-)

            I would make one change to allow @CTL-Signup’s original asterisks (which I assume were marking either the “right” answer or the “selected” answer) to be preserved, which in my tests seems to work by modifying the first

            SEARCH (?-s)^\R|\R(\*?\l\))|(.+)

            Explanation: the same as Guy’s, except allow zero or one asterisk before the lowercase letter: \* indicates a literal asterisk; ? indicates “match 0 or 1”.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors