• Login
Community
  • Login

enclose each character of string in {}

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
6 Posts 4 Posters 797 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.
  • B
    Bill Kristy
    last edited by Apr 27, 2024, 11:41 PM

    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?

    P 1 Reply Last reply Apr 28, 2024, 12:14 AM Reply Quote 0
    • P
      PeterJones @Bill Kristy
      last edited by PeterJones Apr 28, 2024, 8:01 PM Apr 28, 2024, 12:14 AM

      @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
      B A 2 Replies Last reply Apr 28, 2024, 3:59 PM Reply Quote 4
      • B
        Bill Kristy @PeterJones
        last edited by Apr 28, 2024, 3:59 PM

        @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.

        M 1 Reply Last reply Apr 28, 2024, 4:02 PM Reply Quote 0
        • A
          Alan Kilborn @PeterJones
          last edited by Apr 28, 2024, 4:00 PM

          I think @PeterJones made a typo; should be:

          Replace With = {$0}

          B 1 Reply Last reply Apr 28, 2024, 4:17 PM Reply Quote 2
          • M
            mkupper @Bill Kristy
            last edited by mkupper Apr 28, 2024, 4:05 PM Apr 28, 2024, 4:02 PM

            @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
            • B
              Bill Kristy @Alan Kilborn
              last edited by Apr 28, 2024, 4:17 PM

              @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
              5 out of 6
              • First post
                5/6
                Last post
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors