Looking for characters within a string












5















I'm looking for a solution that checks if "alien characters" are contained in a string.



I found Check if a string contains a given character, which looks for one character only. However, I can't adopt this to my needs.



I.E.: Let the main string be asdf.



check{asdf}{asdfgh} should return true, because my main string is a true subset of my string asdfgh which contains non-alien characters.



check{asdf}{hgfdsa} should return true, too. Same as check{adfs}{hdagsf} - Sequence of chars doesn't matter, only occurence.



check{asdf}{asdghj} should return false, because the f character in main string is an alien as it is not in asdghj.



Any ideas welcome.










share|improve this question









New contributor




StringChecker is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    5















    I'm looking for a solution that checks if "alien characters" are contained in a string.



    I found Check if a string contains a given character, which looks for one character only. However, I can't adopt this to my needs.



    I.E.: Let the main string be asdf.



    check{asdf}{asdfgh} should return true, because my main string is a true subset of my string asdfgh which contains non-alien characters.



    check{asdf}{hgfdsa} should return true, too. Same as check{adfs}{hdagsf} - Sequence of chars doesn't matter, only occurence.



    check{asdf}{asdghj} should return false, because the f character in main string is an alien as it is not in asdghj.



    Any ideas welcome.










    share|improve this question









    New contributor




    StringChecker is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.























      5












      5








      5


      0






      I'm looking for a solution that checks if "alien characters" are contained in a string.



      I found Check if a string contains a given character, which looks for one character only. However, I can't adopt this to my needs.



      I.E.: Let the main string be asdf.



      check{asdf}{asdfgh} should return true, because my main string is a true subset of my string asdfgh which contains non-alien characters.



      check{asdf}{hgfdsa} should return true, too. Same as check{adfs}{hdagsf} - Sequence of chars doesn't matter, only occurence.



      check{asdf}{asdghj} should return false, because the f character in main string is an alien as it is not in asdghj.



      Any ideas welcome.










      share|improve this question









      New contributor




      StringChecker is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.












      I'm looking for a solution that checks if "alien characters" are contained in a string.



      I found Check if a string contains a given character, which looks for one character only. However, I can't adopt this to my needs.



      I.E.: Let the main string be asdf.



      check{asdf}{asdfgh} should return true, because my main string is a true subset of my string asdfgh which contains non-alien characters.



      check{asdf}{hgfdsa} should return true, too. Same as check{adfs}{hdagsf} - Sequence of chars doesn't matter, only occurence.



      check{asdf}{asdghj} should return false, because the f character in main string is an alien as it is not in asdghj.



      Any ideas welcome.







      comparison






      share|improve this question









      New contributor




      StringChecker is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      StringChecker is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited 2 days ago









      JouleV

      2,352628




      2,352628






      New contributor




      StringChecker is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 2 days ago









      StringCheckerStringChecker

      283




      283




      New contributor




      StringChecker is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      StringChecker is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      StringChecker is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          2 Answers
          2






          active

          oldest

          votes


















          6














          documentclass{article}

          usepackage{xinttools}

          makeatletter
          newcommandmycheck[2]{%
          xintFor*##1in{#1}:
          {%
          in@{##1}{#2}%
          unlessifin@expandafterxintBreakForfi
          }%
          ifin@expandafter@firstoftwoelseexpandafter@secondoftwofi
          }
          makeatother

          newcommandtest[2]{#1 in #2 ? mycheck{#1}{#2}{TRUE}{FALSE}}
          begin{document}

          test{asdf}{asdfgh}

          test{asdf}{hgfdsa}

          test{asdf}{asdghj}
          end{document}


          enter image description here






          share|improve this answer



















          • 1





            @StringChecker completely forgot to say that with active characters you must use braces like this test{{é}{ç}{à}}{pàqçzé}, test{{é}{ç}{à}}{pàqzé}, with pdflatex (not with lualatex, xelatex). This applies to Babel shorhands too, naturally. And, with braces you can apply mycheck also to macros, even undefined mycheck{{error}{undefined}}{aberrorcundefinedd}{TRUE}{FALSE} (can't use test here which will try to "print" #1={error}{undefined} and #2 same problem)

            – jfbu
            2 days ago











          • reinserting my comment which can be useful for passers-bye that the case of empty list of characters as first argument is undecided (OP said it did not matter). Simply add in@true or in@false before the xintFor* loop depending on what is expected in case of empty list replacing the asdf of example.

            – jfbu
            yesterday



















          8














          You can test each item in the first string for being in the second string; at any “non match” stop and return false.



          documentclass{article}
          usepackage{xparse}

          ExplSyntaxOn

          NewDocumentCommand{checkTF}{mmmm}
          {
          stringchecker_if_string_in:nnTF { #1 } { #2 } { #3 } { #4 }
          }

          bool_new:N l__stringchecker_temp_bool

          prg_new_protected_conditional:Nnn stringchecker_if_string_in:nn { T, F, TF }
          {
          % set the temporary boolean to true; it will remain such
          % unless a nonmatch will happen
          bool_set_true:N l__stringchecker_temp_bool
          % map over the substring to find
          str_map_inline:nn { #1 }
          {
          % do nothing if there is a match; ##1 is the current item, #2 the string to search in
          str_if_in:nnF { #2 } { ##1 }
          {
          % a nonmatch breaks the mapping and sets the boolean to false
          str_map_break:n { bool_set_false:N l__stringchecker_temp_bool }
          }
          }
          bool_if:NTF l__stringchecker_temp_bool
          {% there was no nonmatch, return true
          prg_return_true:
          }
          {% a nonmatch was found, return false
          prg_return_false:
          }
          }
          ExplSyntaxOff

          begin{document}

          checkTF{asdf}{asdfgh}{TRUE}{FALSE}

          checkTF{asdf}{hgfdsa}{TRUE}{FALSE}

          checkTF{asdf}{asdghj}{TRUE}{FALSE}

          checkTF{}{asdghj}{TRUE}{FALSE}

          checkTF{a}{}{TRUE}{FALSE}

          end{document}


          enter image description here



          A slightly more efficient version that absorbs one token at a time from the first argument.



          documentclass{article}
          usepackage{xparse}

          ExplSyntaxOn

          NewDocumentCommand{checkTF}{mmmm}
          {
          stringchecker_if_string_in:nnTF { #1 } { #2 } { #3 } { #4 }
          }

          prg_new_protected_conditional:Nnn stringchecker_if_string_in:nn { T, F, TF }
          {
          __stringchecker_check:nN { #2 } #1 q_nil
          }

          cs_new_protected:Nn __stringchecker_check:nN
          {
          quark_if_nil:NTF #2
          {
          prg_return_true:
          }
          {
          str_if_in:nnTF { #1 } { #2 }
          {
          __stringchecker_check:nN { #1 }
          }
          {
          __stringchecker_stop:w
          }
          }
          }
          cs_new:Npn __stringchecker_stop:w #1 q_nil
          {
          prg_return_false:
          }
          ExplSyntaxOff

          begin{document}

          checkTF{asdf}{asdfgh}{TRUE}{FALSE}

          checkTF{asdf}{hgfdsa}{TRUE}{FALSE}

          checkTF{asdf}{asdghj}{TRUE}{FALSE}

          checkTF{}{asdghj}{TRUE}{FALSE}

          checkTF{a}{}{TRUE}{FALSE}

          end{document}





          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',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });






            StringChecker is a new contributor. Be nice, and check out our Code of Conduct.










            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f469959%2flooking-for-characters-within-a-string%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            6














            documentclass{article}

            usepackage{xinttools}

            makeatletter
            newcommandmycheck[2]{%
            xintFor*##1in{#1}:
            {%
            in@{##1}{#2}%
            unlessifin@expandafterxintBreakForfi
            }%
            ifin@expandafter@firstoftwoelseexpandafter@secondoftwofi
            }
            makeatother

            newcommandtest[2]{#1 in #2 ? mycheck{#1}{#2}{TRUE}{FALSE}}
            begin{document}

            test{asdf}{asdfgh}

            test{asdf}{hgfdsa}

            test{asdf}{asdghj}
            end{document}


            enter image description here






            share|improve this answer



















            • 1





              @StringChecker completely forgot to say that with active characters you must use braces like this test{{é}{ç}{à}}{pàqçzé}, test{{é}{ç}{à}}{pàqzé}, with pdflatex (not with lualatex, xelatex). This applies to Babel shorhands too, naturally. And, with braces you can apply mycheck also to macros, even undefined mycheck{{error}{undefined}}{aberrorcundefinedd}{TRUE}{FALSE} (can't use test here which will try to "print" #1={error}{undefined} and #2 same problem)

              – jfbu
              2 days ago











            • reinserting my comment which can be useful for passers-bye that the case of empty list of characters as first argument is undecided (OP said it did not matter). Simply add in@true or in@false before the xintFor* loop depending on what is expected in case of empty list replacing the asdf of example.

              – jfbu
              yesterday
















            6














            documentclass{article}

            usepackage{xinttools}

            makeatletter
            newcommandmycheck[2]{%
            xintFor*##1in{#1}:
            {%
            in@{##1}{#2}%
            unlessifin@expandafterxintBreakForfi
            }%
            ifin@expandafter@firstoftwoelseexpandafter@secondoftwofi
            }
            makeatother

            newcommandtest[2]{#1 in #2 ? mycheck{#1}{#2}{TRUE}{FALSE}}
            begin{document}

            test{asdf}{asdfgh}

            test{asdf}{hgfdsa}

            test{asdf}{asdghj}
            end{document}


            enter image description here






            share|improve this answer



















            • 1





              @StringChecker completely forgot to say that with active characters you must use braces like this test{{é}{ç}{à}}{pàqçzé}, test{{é}{ç}{à}}{pàqzé}, with pdflatex (not with lualatex, xelatex). This applies to Babel shorhands too, naturally. And, with braces you can apply mycheck also to macros, even undefined mycheck{{error}{undefined}}{aberrorcundefinedd}{TRUE}{FALSE} (can't use test here which will try to "print" #1={error}{undefined} and #2 same problem)

              – jfbu
              2 days ago











            • reinserting my comment which can be useful for passers-bye that the case of empty list of characters as first argument is undecided (OP said it did not matter). Simply add in@true or in@false before the xintFor* loop depending on what is expected in case of empty list replacing the asdf of example.

              – jfbu
              yesterday














            6












            6








            6







            documentclass{article}

            usepackage{xinttools}

            makeatletter
            newcommandmycheck[2]{%
            xintFor*##1in{#1}:
            {%
            in@{##1}{#2}%
            unlessifin@expandafterxintBreakForfi
            }%
            ifin@expandafter@firstoftwoelseexpandafter@secondoftwofi
            }
            makeatother

            newcommandtest[2]{#1 in #2 ? mycheck{#1}{#2}{TRUE}{FALSE}}
            begin{document}

            test{asdf}{asdfgh}

            test{asdf}{hgfdsa}

            test{asdf}{asdghj}
            end{document}


            enter image description here






            share|improve this answer













            documentclass{article}

            usepackage{xinttools}

            makeatletter
            newcommandmycheck[2]{%
            xintFor*##1in{#1}:
            {%
            in@{##1}{#2}%
            unlessifin@expandafterxintBreakForfi
            }%
            ifin@expandafter@firstoftwoelseexpandafter@secondoftwofi
            }
            makeatother

            newcommandtest[2]{#1 in #2 ? mycheck{#1}{#2}{TRUE}{FALSE}}
            begin{document}

            test{asdf}{asdfgh}

            test{asdf}{hgfdsa}

            test{asdf}{asdghj}
            end{document}


            enter image description here







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 2 days ago









            jfbujfbu

            46.5k66148




            46.5k66148








            • 1





              @StringChecker completely forgot to say that with active characters you must use braces like this test{{é}{ç}{à}}{pàqçzé}, test{{é}{ç}{à}}{pàqzé}, with pdflatex (not with lualatex, xelatex). This applies to Babel shorhands too, naturally. And, with braces you can apply mycheck also to macros, even undefined mycheck{{error}{undefined}}{aberrorcundefinedd}{TRUE}{FALSE} (can't use test here which will try to "print" #1={error}{undefined} and #2 same problem)

              – jfbu
              2 days ago











            • reinserting my comment which can be useful for passers-bye that the case of empty list of characters as first argument is undecided (OP said it did not matter). Simply add in@true or in@false before the xintFor* loop depending on what is expected in case of empty list replacing the asdf of example.

              – jfbu
              yesterday














            • 1





              @StringChecker completely forgot to say that with active characters you must use braces like this test{{é}{ç}{à}}{pàqçzé}, test{{é}{ç}{à}}{pàqzé}, with pdflatex (not with lualatex, xelatex). This applies to Babel shorhands too, naturally. And, with braces you can apply mycheck also to macros, even undefined mycheck{{error}{undefined}}{aberrorcundefinedd}{TRUE}{FALSE} (can't use test here which will try to "print" #1={error}{undefined} and #2 same problem)

              – jfbu
              2 days ago











            • reinserting my comment which can be useful for passers-bye that the case of empty list of characters as first argument is undecided (OP said it did not matter). Simply add in@true or in@false before the xintFor* loop depending on what is expected in case of empty list replacing the asdf of example.

              – jfbu
              yesterday








            1




            1





            @StringChecker completely forgot to say that with active characters you must use braces like this test{{é}{ç}{à}}{pàqçzé}, test{{é}{ç}{à}}{pàqzé}, with pdflatex (not with lualatex, xelatex). This applies to Babel shorhands too, naturally. And, with braces you can apply mycheck also to macros, even undefined mycheck{{error}{undefined}}{aberrorcundefinedd}{TRUE}{FALSE} (can't use test here which will try to "print" #1={error}{undefined} and #2 same problem)

            – jfbu
            2 days ago





            @StringChecker completely forgot to say that with active characters you must use braces like this test{{é}{ç}{à}}{pàqçzé}, test{{é}{ç}{à}}{pàqzé}, with pdflatex (not with lualatex, xelatex). This applies to Babel shorhands too, naturally. And, with braces you can apply mycheck also to macros, even undefined mycheck{{error}{undefined}}{aberrorcundefinedd}{TRUE}{FALSE} (can't use test here which will try to "print" #1={error}{undefined} and #2 same problem)

            – jfbu
            2 days ago













            reinserting my comment which can be useful for passers-bye that the case of empty list of characters as first argument is undecided (OP said it did not matter). Simply add in@true or in@false before the xintFor* loop depending on what is expected in case of empty list replacing the asdf of example.

            – jfbu
            yesterday





            reinserting my comment which can be useful for passers-bye that the case of empty list of characters as first argument is undecided (OP said it did not matter). Simply add in@true or in@false before the xintFor* loop depending on what is expected in case of empty list replacing the asdf of example.

            – jfbu
            yesterday











            8














            You can test each item in the first string for being in the second string; at any “non match” stop and return false.



            documentclass{article}
            usepackage{xparse}

            ExplSyntaxOn

            NewDocumentCommand{checkTF}{mmmm}
            {
            stringchecker_if_string_in:nnTF { #1 } { #2 } { #3 } { #4 }
            }

            bool_new:N l__stringchecker_temp_bool

            prg_new_protected_conditional:Nnn stringchecker_if_string_in:nn { T, F, TF }
            {
            % set the temporary boolean to true; it will remain such
            % unless a nonmatch will happen
            bool_set_true:N l__stringchecker_temp_bool
            % map over the substring to find
            str_map_inline:nn { #1 }
            {
            % do nothing if there is a match; ##1 is the current item, #2 the string to search in
            str_if_in:nnF { #2 } { ##1 }
            {
            % a nonmatch breaks the mapping and sets the boolean to false
            str_map_break:n { bool_set_false:N l__stringchecker_temp_bool }
            }
            }
            bool_if:NTF l__stringchecker_temp_bool
            {% there was no nonmatch, return true
            prg_return_true:
            }
            {% a nonmatch was found, return false
            prg_return_false:
            }
            }
            ExplSyntaxOff

            begin{document}

            checkTF{asdf}{asdfgh}{TRUE}{FALSE}

            checkTF{asdf}{hgfdsa}{TRUE}{FALSE}

            checkTF{asdf}{asdghj}{TRUE}{FALSE}

            checkTF{}{asdghj}{TRUE}{FALSE}

            checkTF{a}{}{TRUE}{FALSE}

            end{document}


            enter image description here



            A slightly more efficient version that absorbs one token at a time from the first argument.



            documentclass{article}
            usepackage{xparse}

            ExplSyntaxOn

            NewDocumentCommand{checkTF}{mmmm}
            {
            stringchecker_if_string_in:nnTF { #1 } { #2 } { #3 } { #4 }
            }

            prg_new_protected_conditional:Nnn stringchecker_if_string_in:nn { T, F, TF }
            {
            __stringchecker_check:nN { #2 } #1 q_nil
            }

            cs_new_protected:Nn __stringchecker_check:nN
            {
            quark_if_nil:NTF #2
            {
            prg_return_true:
            }
            {
            str_if_in:nnTF { #1 } { #2 }
            {
            __stringchecker_check:nN { #1 }
            }
            {
            __stringchecker_stop:w
            }
            }
            }
            cs_new:Npn __stringchecker_stop:w #1 q_nil
            {
            prg_return_false:
            }
            ExplSyntaxOff

            begin{document}

            checkTF{asdf}{asdfgh}{TRUE}{FALSE}

            checkTF{asdf}{hgfdsa}{TRUE}{FALSE}

            checkTF{asdf}{asdghj}{TRUE}{FALSE}

            checkTF{}{asdghj}{TRUE}{FALSE}

            checkTF{a}{}{TRUE}{FALSE}

            end{document}





            share|improve this answer






























              8














              You can test each item in the first string for being in the second string; at any “non match” stop and return false.



              documentclass{article}
              usepackage{xparse}

              ExplSyntaxOn

              NewDocumentCommand{checkTF}{mmmm}
              {
              stringchecker_if_string_in:nnTF { #1 } { #2 } { #3 } { #4 }
              }

              bool_new:N l__stringchecker_temp_bool

              prg_new_protected_conditional:Nnn stringchecker_if_string_in:nn { T, F, TF }
              {
              % set the temporary boolean to true; it will remain such
              % unless a nonmatch will happen
              bool_set_true:N l__stringchecker_temp_bool
              % map over the substring to find
              str_map_inline:nn { #1 }
              {
              % do nothing if there is a match; ##1 is the current item, #2 the string to search in
              str_if_in:nnF { #2 } { ##1 }
              {
              % a nonmatch breaks the mapping and sets the boolean to false
              str_map_break:n { bool_set_false:N l__stringchecker_temp_bool }
              }
              }
              bool_if:NTF l__stringchecker_temp_bool
              {% there was no nonmatch, return true
              prg_return_true:
              }
              {% a nonmatch was found, return false
              prg_return_false:
              }
              }
              ExplSyntaxOff

              begin{document}

              checkTF{asdf}{asdfgh}{TRUE}{FALSE}

              checkTF{asdf}{hgfdsa}{TRUE}{FALSE}

              checkTF{asdf}{asdghj}{TRUE}{FALSE}

              checkTF{}{asdghj}{TRUE}{FALSE}

              checkTF{a}{}{TRUE}{FALSE}

              end{document}


              enter image description here



              A slightly more efficient version that absorbs one token at a time from the first argument.



              documentclass{article}
              usepackage{xparse}

              ExplSyntaxOn

              NewDocumentCommand{checkTF}{mmmm}
              {
              stringchecker_if_string_in:nnTF { #1 } { #2 } { #3 } { #4 }
              }

              prg_new_protected_conditional:Nnn stringchecker_if_string_in:nn { T, F, TF }
              {
              __stringchecker_check:nN { #2 } #1 q_nil
              }

              cs_new_protected:Nn __stringchecker_check:nN
              {
              quark_if_nil:NTF #2
              {
              prg_return_true:
              }
              {
              str_if_in:nnTF { #1 } { #2 }
              {
              __stringchecker_check:nN { #1 }
              }
              {
              __stringchecker_stop:w
              }
              }
              }
              cs_new:Npn __stringchecker_stop:w #1 q_nil
              {
              prg_return_false:
              }
              ExplSyntaxOff

              begin{document}

              checkTF{asdf}{asdfgh}{TRUE}{FALSE}

              checkTF{asdf}{hgfdsa}{TRUE}{FALSE}

              checkTF{asdf}{asdghj}{TRUE}{FALSE}

              checkTF{}{asdghj}{TRUE}{FALSE}

              checkTF{a}{}{TRUE}{FALSE}

              end{document}





              share|improve this answer




























                8












                8








                8







                You can test each item in the first string for being in the second string; at any “non match” stop and return false.



                documentclass{article}
                usepackage{xparse}

                ExplSyntaxOn

                NewDocumentCommand{checkTF}{mmmm}
                {
                stringchecker_if_string_in:nnTF { #1 } { #2 } { #3 } { #4 }
                }

                bool_new:N l__stringchecker_temp_bool

                prg_new_protected_conditional:Nnn stringchecker_if_string_in:nn { T, F, TF }
                {
                % set the temporary boolean to true; it will remain such
                % unless a nonmatch will happen
                bool_set_true:N l__stringchecker_temp_bool
                % map over the substring to find
                str_map_inline:nn { #1 }
                {
                % do nothing if there is a match; ##1 is the current item, #2 the string to search in
                str_if_in:nnF { #2 } { ##1 }
                {
                % a nonmatch breaks the mapping and sets the boolean to false
                str_map_break:n { bool_set_false:N l__stringchecker_temp_bool }
                }
                }
                bool_if:NTF l__stringchecker_temp_bool
                {% there was no nonmatch, return true
                prg_return_true:
                }
                {% a nonmatch was found, return false
                prg_return_false:
                }
                }
                ExplSyntaxOff

                begin{document}

                checkTF{asdf}{asdfgh}{TRUE}{FALSE}

                checkTF{asdf}{hgfdsa}{TRUE}{FALSE}

                checkTF{asdf}{asdghj}{TRUE}{FALSE}

                checkTF{}{asdghj}{TRUE}{FALSE}

                checkTF{a}{}{TRUE}{FALSE}

                end{document}


                enter image description here



                A slightly more efficient version that absorbs one token at a time from the first argument.



                documentclass{article}
                usepackage{xparse}

                ExplSyntaxOn

                NewDocumentCommand{checkTF}{mmmm}
                {
                stringchecker_if_string_in:nnTF { #1 } { #2 } { #3 } { #4 }
                }

                prg_new_protected_conditional:Nnn stringchecker_if_string_in:nn { T, F, TF }
                {
                __stringchecker_check:nN { #2 } #1 q_nil
                }

                cs_new_protected:Nn __stringchecker_check:nN
                {
                quark_if_nil:NTF #2
                {
                prg_return_true:
                }
                {
                str_if_in:nnTF { #1 } { #2 }
                {
                __stringchecker_check:nN { #1 }
                }
                {
                __stringchecker_stop:w
                }
                }
                }
                cs_new:Npn __stringchecker_stop:w #1 q_nil
                {
                prg_return_false:
                }
                ExplSyntaxOff

                begin{document}

                checkTF{asdf}{asdfgh}{TRUE}{FALSE}

                checkTF{asdf}{hgfdsa}{TRUE}{FALSE}

                checkTF{asdf}{asdghj}{TRUE}{FALSE}

                checkTF{}{asdghj}{TRUE}{FALSE}

                checkTF{a}{}{TRUE}{FALSE}

                end{document}





                share|improve this answer















                You can test each item in the first string for being in the second string; at any “non match” stop and return false.



                documentclass{article}
                usepackage{xparse}

                ExplSyntaxOn

                NewDocumentCommand{checkTF}{mmmm}
                {
                stringchecker_if_string_in:nnTF { #1 } { #2 } { #3 } { #4 }
                }

                bool_new:N l__stringchecker_temp_bool

                prg_new_protected_conditional:Nnn stringchecker_if_string_in:nn { T, F, TF }
                {
                % set the temporary boolean to true; it will remain such
                % unless a nonmatch will happen
                bool_set_true:N l__stringchecker_temp_bool
                % map over the substring to find
                str_map_inline:nn { #1 }
                {
                % do nothing if there is a match; ##1 is the current item, #2 the string to search in
                str_if_in:nnF { #2 } { ##1 }
                {
                % a nonmatch breaks the mapping and sets the boolean to false
                str_map_break:n { bool_set_false:N l__stringchecker_temp_bool }
                }
                }
                bool_if:NTF l__stringchecker_temp_bool
                {% there was no nonmatch, return true
                prg_return_true:
                }
                {% a nonmatch was found, return false
                prg_return_false:
                }
                }
                ExplSyntaxOff

                begin{document}

                checkTF{asdf}{asdfgh}{TRUE}{FALSE}

                checkTF{asdf}{hgfdsa}{TRUE}{FALSE}

                checkTF{asdf}{asdghj}{TRUE}{FALSE}

                checkTF{}{asdghj}{TRUE}{FALSE}

                checkTF{a}{}{TRUE}{FALSE}

                end{document}


                enter image description here



                A slightly more efficient version that absorbs one token at a time from the first argument.



                documentclass{article}
                usepackage{xparse}

                ExplSyntaxOn

                NewDocumentCommand{checkTF}{mmmm}
                {
                stringchecker_if_string_in:nnTF { #1 } { #2 } { #3 } { #4 }
                }

                prg_new_protected_conditional:Nnn stringchecker_if_string_in:nn { T, F, TF }
                {
                __stringchecker_check:nN { #2 } #1 q_nil
                }

                cs_new_protected:Nn __stringchecker_check:nN
                {
                quark_if_nil:NTF #2
                {
                prg_return_true:
                }
                {
                str_if_in:nnTF { #1 } { #2 }
                {
                __stringchecker_check:nN { #1 }
                }
                {
                __stringchecker_stop:w
                }
                }
                }
                cs_new:Npn __stringchecker_stop:w #1 q_nil
                {
                prg_return_false:
                }
                ExplSyntaxOff

                begin{document}

                checkTF{asdf}{asdfgh}{TRUE}{FALSE}

                checkTF{asdf}{hgfdsa}{TRUE}{FALSE}

                checkTF{asdf}{asdghj}{TRUE}{FALSE}

                checkTF{}{asdghj}{TRUE}{FALSE}

                checkTF{a}{}{TRUE}{FALSE}

                end{document}






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 2 days ago

























                answered 2 days ago









                egregegreg

                712k8618933179




                712k8618933179






















                    StringChecker is a new contributor. Be nice, and check out our Code of Conduct.










                    draft saved

                    draft discarded


















                    StringChecker is a new contributor. Be nice, and check out our Code of Conduct.













                    StringChecker is a new contributor. Be nice, and check out our Code of Conduct.












                    StringChecker is a new contributor. Be nice, and check out our Code of Conduct.
















                    Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f469959%2flooking-for-characters-within-a-string%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Paul Cézanne

                    UIScrollView CustomStickyHeader Resize height generates problems when scroll is too fast

                    Angular material date-picker (MatDatepicker) auto completes the date on focus out