Community
    • Login

    enclose each character of string in {}

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    6 Posts 4 Posters 404 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.
    • Bill KristyB
      Bill Kristy
      last edited by

      I have a long string of random characters, and I need each character enclosed in brackets.

      For example, I want to transform
      abcd
      into
      {a}{b}{c]{d}

      Can I do this with Notepad++? Or alternative suggestion please?

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

        @Bill-Kristy ,

        Using

        • Search Mode = Regular Expression
        • Find What= .
        • and Replace With = {$1}

        you should get what you want.

        update: sorry for the typo: as others clarified below, should be {$0}

        ----

        Useful References

        • Please Read Before Posting
        • Template for Search/Replace Questions
        • Formatting Forum Posts
        • Notepad++ Online User Manual: Searching/Regex
        • FAQ: Where to find other regular expressions (regex) documentation
        Bill KristyB Alan KilbornA 2 Replies Last reply Reply Quote 4
        • Bill KristyB
          Bill Kristy @PeterJones
          last edited by

          @PeterJones Thank you very much for your reply!

          Close, but what that got me was:
          {}{}{]{}

          In other words, a pair of empty brackets for each character.

          mkupperM 1 Reply Last reply Reply Quote 0
          • Alan KilbornA
            Alan Kilborn @PeterJones
            last edited by

            I think @PeterJones made a typo; should be:

            Replace With = {$0}

            Bill KristyB 1 Reply Last reply Reply Quote 2
            • mkupperM
              mkupper @Bill Kristy
              last edited by mkupper

              @Bill-Kristy, @PeterJones had a typo.

              Regular expression search for .
              Replace with {$0}

              An alternative is to search for (.) and to replace with {$1}

              $0 in a replacement part is the entire thing that was matched in the search part.
              $1 in a replacement part is the first capture group which is the thing in (parentheses)

              1 Reply Last reply Reply Quote 1
              • Bill KristyB
                Bill Kristy @Alan Kilborn
                last edited by

                @Alan-Kilborn @mkupper Thank you very much everyone, {$0} did the trick! Pure gold for me, thanks again!

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