Remove backslash from string

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite
1












I am defining a new command, where the input contains backslash, which is to be removed later, hence I am searching for a way to accomplish that. The following example removes backslash when it is in-front of the string, but fails when the slash is in-between a string.



documentclassarticle
makeatletter
newcommandremoveabs[1]%
ifcatrelaxnoexpand#1%
expandafterexpandafterexpandafter@gobbleexpandafterstring
fi
#1%

makeatother
begindocument
removeabsthe slash is removed here
removeabsbut not here
enddocument


Does anybody know how to remove the backslash, even if it is in-between a string ?










share|improve this question



























    up vote
    2
    down vote

    favorite
    1












    I am defining a new command, where the input contains backslash, which is to be removed later, hence I am searching for a way to accomplish that. The following example removes backslash when it is in-front of the string, but fails when the slash is in-between a string.



    documentclassarticle
    makeatletter
    newcommandremoveabs[1]%
    ifcatrelaxnoexpand#1%
    expandafterexpandafterexpandafter@gobbleexpandafterstring
    fi
    #1%

    makeatother
    begindocument
    removeabsthe slash is removed here
    removeabsbut not here
    enddocument


    Does anybody know how to remove the backslash, even if it is in-between a string ?










    share|improve this question

























      up vote
      2
      down vote

      favorite
      1









      up vote
      2
      down vote

      favorite
      1






      1





      I am defining a new command, where the input contains backslash, which is to be removed later, hence I am searching for a way to accomplish that. The following example removes backslash when it is in-front of the string, but fails when the slash is in-between a string.



      documentclassarticle
      makeatletter
      newcommandremoveabs[1]%
      ifcatrelaxnoexpand#1%
      expandafterexpandafterexpandafter@gobbleexpandafterstring
      fi
      #1%

      makeatother
      begindocument
      removeabsthe slash is removed here
      removeabsbut not here
      enddocument


      Does anybody know how to remove the backslash, even if it is in-between a string ?










      share|improve this question















      I am defining a new command, where the input contains backslash, which is to be removed later, hence I am searching for a way to accomplish that. The following example removes backslash when it is in-front of the string, but fails when the slash is in-between a string.



      documentclassarticle
      makeatletter
      newcommandremoveabs[1]%
      ifcatrelaxnoexpand#1%
      expandafterexpandafterexpandafter@gobbleexpandafterstring
      fi
      #1%

      makeatother
      begindocument
      removeabsthe slash is removed here
      removeabsbut not here
      enddocument


      Does anybody know how to remove the backslash, even if it is in-between a string ?







      macros






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 1 hour ago

























      asked 1 hour ago









      Ashok

      310111




      310111




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          4
          down vote



          accepted










          documentclassarticle
          newcommandremoveabs[1]%
          %catcode92=9 endlinechar-1 scantokensexpandafterdetokenize#1%
          catcode92=9 endlinechar-1 scantokens#1%

          begindocument
          removeabsthe slash is removed here
          removeabsand also here+++
          enddocument


          But your use case is not really known...



          enter image description here



          As pointed out by @A.Ellett there is no real need for detokenize. Even, maybe you want to preserve things like math:



          documentclassarticle
          newcommandremoveabs[1]%
          catcode92=9 endlinechar-1 scantokens#1%

          begindocument
          removeabsthe slash $E=mc^2$ is removed here
          removeabsand also here+++
          enddocument


          enter image description here



          Perhaps you want to store in macro, the following shows how to do it (but the x here is used and discarded).



          Notice though that therein you should not be some active character with a definition not compatible with an edef. The ~ and the UTF-8 things are OK.



          documentclassarticle
          usepackage[T1]fontenc
          newcommandremoveabs[1]%
          catcode92=9 endlinechar-1 everyeofnoexpandedefxscantokens#1x%

          begindocument
          removeabsthe slash $E=mc^2$ is~~~~removed here
          removeabsand also éééé here+++
          enddocument


          enter image description here



          Thanks to @A.Ellett!






          share|improve this answer


















          • 2




            Is detokenize really necessary there? Won't scantokens alone handle everything?
            – A.Ellett
            52 mins ago






          • 1




            @A.Ellett you are absolutely right, but the OP was mentioning "strings"... I will edit.
            – jfbu
            43 mins ago

















          up vote
          0
          down vote













          With expl3:



          documentclassarticle
          usepackagexparse

          ExplSyntaxOn

          NewDocumentCommandremovebsm

          tl_set:Nn l_tmpa_tl #1
          regex_replace_all:nnN cC. ccs_to_str:N l_tmpa_tl
          tl_use:N l_tmpa_tl


          ExplSyntaxOff

          begindocument

          removebsthe slash is removed here

          removebsthe slashes are removed here

          removebsand also here

          enddocument


          Note that the space after the in the first case doesn't disappear, because it was ignored to begin with.



          enter image description here






          share|improve this answer




















            Your Answer







            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "85"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f454641%2fremove-backslash-from-string%23new-answer', 'question_page');

            );

            Post as a guest






























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            4
            down vote



            accepted










            documentclassarticle
            newcommandremoveabs[1]%
            %catcode92=9 endlinechar-1 scantokensexpandafterdetokenize#1%
            catcode92=9 endlinechar-1 scantokens#1%

            begindocument
            removeabsthe slash is removed here
            removeabsand also here+++
            enddocument


            But your use case is not really known...



            enter image description here



            As pointed out by @A.Ellett there is no real need for detokenize. Even, maybe you want to preserve things like math:



            documentclassarticle
            newcommandremoveabs[1]%
            catcode92=9 endlinechar-1 scantokens#1%

            begindocument
            removeabsthe slash $E=mc^2$ is removed here
            removeabsand also here+++
            enddocument


            enter image description here



            Perhaps you want to store in macro, the following shows how to do it (but the x here is used and discarded).



            Notice though that therein you should not be some active character with a definition not compatible with an edef. The ~ and the UTF-8 things are OK.



            documentclassarticle
            usepackage[T1]fontenc
            newcommandremoveabs[1]%
            catcode92=9 endlinechar-1 everyeofnoexpandedefxscantokens#1x%

            begindocument
            removeabsthe slash $E=mc^2$ is~~~~removed here
            removeabsand also éééé here+++
            enddocument


            enter image description here



            Thanks to @A.Ellett!






            share|improve this answer


















            • 2




              Is detokenize really necessary there? Won't scantokens alone handle everything?
              – A.Ellett
              52 mins ago






            • 1




              @A.Ellett you are absolutely right, but the OP was mentioning "strings"... I will edit.
              – jfbu
              43 mins ago














            up vote
            4
            down vote



            accepted










            documentclassarticle
            newcommandremoveabs[1]%
            %catcode92=9 endlinechar-1 scantokensexpandafterdetokenize#1%
            catcode92=9 endlinechar-1 scantokens#1%

            begindocument
            removeabsthe slash is removed here
            removeabsand also here+++
            enddocument


            But your use case is not really known...



            enter image description here



            As pointed out by @A.Ellett there is no real need for detokenize. Even, maybe you want to preserve things like math:



            documentclassarticle
            newcommandremoveabs[1]%
            catcode92=9 endlinechar-1 scantokens#1%

            begindocument
            removeabsthe slash $E=mc^2$ is removed here
            removeabsand also here+++
            enddocument


            enter image description here



            Perhaps you want to store in macro, the following shows how to do it (but the x here is used and discarded).



            Notice though that therein you should not be some active character with a definition not compatible with an edef. The ~ and the UTF-8 things are OK.



            documentclassarticle
            usepackage[T1]fontenc
            newcommandremoveabs[1]%
            catcode92=9 endlinechar-1 everyeofnoexpandedefxscantokens#1x%

            begindocument
            removeabsthe slash $E=mc^2$ is~~~~removed here
            removeabsand also éééé here+++
            enddocument


            enter image description here



            Thanks to @A.Ellett!






            share|improve this answer


















            • 2




              Is detokenize really necessary there? Won't scantokens alone handle everything?
              – A.Ellett
              52 mins ago






            • 1




              @A.Ellett you are absolutely right, but the OP was mentioning "strings"... I will edit.
              – jfbu
              43 mins ago












            up vote
            4
            down vote



            accepted







            up vote
            4
            down vote



            accepted






            documentclassarticle
            newcommandremoveabs[1]%
            %catcode92=9 endlinechar-1 scantokensexpandafterdetokenize#1%
            catcode92=9 endlinechar-1 scantokens#1%

            begindocument
            removeabsthe slash is removed here
            removeabsand also here+++
            enddocument


            But your use case is not really known...



            enter image description here



            As pointed out by @A.Ellett there is no real need for detokenize. Even, maybe you want to preserve things like math:



            documentclassarticle
            newcommandremoveabs[1]%
            catcode92=9 endlinechar-1 scantokens#1%

            begindocument
            removeabsthe slash $E=mc^2$ is removed here
            removeabsand also here+++
            enddocument


            enter image description here



            Perhaps you want to store in macro, the following shows how to do it (but the x here is used and discarded).



            Notice though that therein you should not be some active character with a definition not compatible with an edef. The ~ and the UTF-8 things are OK.



            documentclassarticle
            usepackage[T1]fontenc
            newcommandremoveabs[1]%
            catcode92=9 endlinechar-1 everyeofnoexpandedefxscantokens#1x%

            begindocument
            removeabsthe slash $E=mc^2$ is~~~~removed here
            removeabsand also éééé here+++
            enddocument


            enter image description here



            Thanks to @A.Ellett!






            share|improve this answer














            documentclassarticle
            newcommandremoveabs[1]%
            %catcode92=9 endlinechar-1 scantokensexpandafterdetokenize#1%
            catcode92=9 endlinechar-1 scantokens#1%

            begindocument
            removeabsthe slash is removed here
            removeabsand also here+++
            enddocument


            But your use case is not really known...



            enter image description here



            As pointed out by @A.Ellett there is no real need for detokenize. Even, maybe you want to preserve things like math:



            documentclassarticle
            newcommandremoveabs[1]%
            catcode92=9 endlinechar-1 scantokens#1%

            begindocument
            removeabsthe slash $E=mc^2$ is removed here
            removeabsand also here+++
            enddocument


            enter image description here



            Perhaps you want to store in macro, the following shows how to do it (but the x here is used and discarded).



            Notice though that therein you should not be some active character with a definition not compatible with an edef. The ~ and the UTF-8 things are OK.



            documentclassarticle
            usepackage[T1]fontenc
            newcommandremoveabs[1]%
            catcode92=9 endlinechar-1 everyeofnoexpandedefxscantokens#1x%

            begindocument
            removeabsthe slash $E=mc^2$ is~~~~removed here
            removeabsand also éééé here+++
            enddocument


            enter image description here



            Thanks to @A.Ellett!







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 36 mins ago

























            answered 1 hour ago









            jfbu

            42.8k64139




            42.8k64139







            • 2




              Is detokenize really necessary there? Won't scantokens alone handle everything?
              – A.Ellett
              52 mins ago






            • 1




              @A.Ellett you are absolutely right, but the OP was mentioning "strings"... I will edit.
              – jfbu
              43 mins ago












            • 2




              Is detokenize really necessary there? Won't scantokens alone handle everything?
              – A.Ellett
              52 mins ago






            • 1




              @A.Ellett you are absolutely right, but the OP was mentioning "strings"... I will edit.
              – jfbu
              43 mins ago







            2




            2




            Is detokenize really necessary there? Won't scantokens alone handle everything?
            – A.Ellett
            52 mins ago




            Is detokenize really necessary there? Won't scantokens alone handle everything?
            – A.Ellett
            52 mins ago




            1




            1




            @A.Ellett you are absolutely right, but the OP was mentioning "strings"... I will edit.
            – jfbu
            43 mins ago




            @A.Ellett you are absolutely right, but the OP was mentioning "strings"... I will edit.
            – jfbu
            43 mins ago










            up vote
            0
            down vote













            With expl3:



            documentclassarticle
            usepackagexparse

            ExplSyntaxOn

            NewDocumentCommandremovebsm

            tl_set:Nn l_tmpa_tl #1
            regex_replace_all:nnN cC. ccs_to_str:N l_tmpa_tl
            tl_use:N l_tmpa_tl


            ExplSyntaxOff

            begindocument

            removebsthe slash is removed here

            removebsthe slashes are removed here

            removebsand also here

            enddocument


            Note that the space after the in the first case doesn't disappear, because it was ignored to begin with.



            enter image description here






            share|improve this answer
























              up vote
              0
              down vote













              With expl3:



              documentclassarticle
              usepackagexparse

              ExplSyntaxOn

              NewDocumentCommandremovebsm

              tl_set:Nn l_tmpa_tl #1
              regex_replace_all:nnN cC. ccs_to_str:N l_tmpa_tl
              tl_use:N l_tmpa_tl


              ExplSyntaxOff

              begindocument

              removebsthe slash is removed here

              removebsthe slashes are removed here

              removebsand also here

              enddocument


              Note that the space after the in the first case doesn't disappear, because it was ignored to begin with.



              enter image description here






              share|improve this answer






















                up vote
                0
                down vote










                up vote
                0
                down vote









                With expl3:



                documentclassarticle
                usepackagexparse

                ExplSyntaxOn

                NewDocumentCommandremovebsm

                tl_set:Nn l_tmpa_tl #1
                regex_replace_all:nnN cC. ccs_to_str:N l_tmpa_tl
                tl_use:N l_tmpa_tl


                ExplSyntaxOff

                begindocument

                removebsthe slash is removed here

                removebsthe slashes are removed here

                removebsand also here

                enddocument


                Note that the space after the in the first case doesn't disappear, because it was ignored to begin with.



                enter image description here






                share|improve this answer












                With expl3:



                documentclassarticle
                usepackagexparse

                ExplSyntaxOn

                NewDocumentCommandremovebsm

                tl_set:Nn l_tmpa_tl #1
                regex_replace_all:nnN cC. ccs_to_str:N l_tmpa_tl
                tl_use:N l_tmpa_tl


                ExplSyntaxOff

                begindocument

                removebsthe slash is removed here

                removebsthe slashes are removed here

                removebsand also here

                enddocument


                Note that the space after the in the first case doesn't disappear, because it was ignored to begin with.



                enter image description here







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 13 mins ago









                egreg

                688k8518323080




                688k8518323080



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f454641%2fremove-backslash-from-string%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Comments

                    Popular posts from this blog

                    Long meetings (6-7 hours a day): Being “babysat” by supervisor

                    Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

                    Confectionery