Find non-case sensitive string in a mixed list of elements? The 2019 Stack Overflow Developer Survey Results Are InBuilding a list recursive with one or more argumentsReturn Functions from parallel execution of moduleFast method to select matrix elements based on a vector of positionsIssue with very large lists in MathematicaFaster position list construction from a “take instructions” listConvert elements of list to stringAdding a collection of neighbors to points in a list, concatenating strings, parallelization/optimizing run-time?Get sublists by pattern?Obtaining the position in a list where the i^th element is bigger than the (i+1)^th elementExtract all instances of variables matching a pattern?

Match Roman Numerals

What is the motivation for a law requiring 2 parties to consent for recording a conversation

How to type a long/em dash `—`

Finding the area between two curves with Integrate

ELI5: Why they say that Israel would have been the fourth country to land a spacecraft on the Moon and why they call it low cost?

How come people say “Would of”?

Does adding complexity mean a more secure cipher?

Why doesn't UInt have a toDouble()?

What can I do if neighbor is blocking my solar panels intentionally

Mathematics of imaging the black hole

Why are there uneven bright areas in this photo of black hole?

Did any laptop computers have a built-in 5 1/4 inch floppy drive?

If climate change impact can be observed in nature, has that had any effect on rural, i.e. farming community, perception of the scientific consensus?

How much of the clove should I use when using big garlic heads?

Is Cinnamon a desktop environment or a window manager? (Or both?)

How do PCB vias affect signal quality?

Getting crown tickets for Statue of Liberty

How to notate time signature switching consistently every measure

What was the last CPU that did not have the x87 floating-point unit built in?

What do these terms in Caesar's Gallic Wars mean?

How can I define good in a religion that claims no moral authority?

Pokemon Turn Based battle (Python)

Falsification in Math vs Science

Why can I use a list index as an indexing variable in a for loop?



Find non-case sensitive string in a mixed list of elements?



The 2019 Stack Overflow Developer Survey Results Are InBuilding a list recursive with one or more argumentsReturn Functions from parallel execution of moduleFast method to select matrix elements based on a vector of positionsIssue with very large lists in MathematicaFaster position list construction from a “take instructions” listConvert elements of list to stringAdding a collection of neighbors to points in a list, concatenating strings, parallelization/optimizing run-time?Get sublists by pattern?Obtaining the position in a list where the i^th element is bigger than the (i+1)^th elementExtract all instances of variables matching a pattern?










3












$begingroup$


Consider an example list with mixed element types, e.g.:



list = 1.234 , a[2] , "Abc" , 4/5 , "acb" ;


I would like to have a function that finds the position of a string, without regard to upper or lower characters, e.g.:



findPosition[list,"abc"]



3,1




Is there a function like that in Mathematica? Or maybe one can implement it with efficient performance?



EDIT:



My current workaround is:



findPosition[list_,str_]:=Position[list/.x_String:>ToLowerCase[x],ToLowerCase[str]]









share|improve this question











$endgroup$
















    3












    $begingroup$


    Consider an example list with mixed element types, e.g.:



    list = 1.234 , a[2] , "Abc" , 4/5 , "acb" ;


    I would like to have a function that finds the position of a string, without regard to upper or lower characters, e.g.:



    findPosition[list,"abc"]



    3,1




    Is there a function like that in Mathematica? Or maybe one can implement it with efficient performance?



    EDIT:



    My current workaround is:



    findPosition[list_,str_]:=Position[list/.x_String:>ToLowerCase[x],ToLowerCase[str]]









    share|improve this question











    $endgroup$














      3












      3








      3





      $begingroup$


      Consider an example list with mixed element types, e.g.:



      list = 1.234 , a[2] , "Abc" , 4/5 , "acb" ;


      I would like to have a function that finds the position of a string, without regard to upper or lower characters, e.g.:



      findPosition[list,"abc"]



      3,1




      Is there a function like that in Mathematica? Or maybe one can implement it with efficient performance?



      EDIT:



      My current workaround is:



      findPosition[list_,str_]:=Position[list/.x_String:>ToLowerCase[x],ToLowerCase[str]]









      share|improve this question











      $endgroup$




      Consider an example list with mixed element types, e.g.:



      list = 1.234 , a[2] , "Abc" , 4/5 , "acb" ;


      I would like to have a function that finds the position of a string, without regard to upper or lower characters, e.g.:



      findPosition[list,"abc"]



      3,1




      Is there a function like that in Mathematica? Or maybe one can implement it with efficient performance?



      EDIT:



      My current workaround is:



      findPosition[list_,str_]:=Position[list/.x_String:>ToLowerCase[x],ToLowerCase[str]]






      list-manipulation function-construction searching






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 30 at 21:21







      Kagaratsch

















      asked Mar 30 at 21:15









      KagaratschKagaratsch

      4,83831348




      4,83831348




















          3 Answers
          3






          active

          oldest

          votes


















          2












          $begingroup$

          Recall that StringMatchQ[] has the IgnoreCase option:



          Position[1.234, a[2], "Abc", 4/5, "acb",
          s_String /; StringMatchQ[s, "abc", IgnoreCase -> True]]
          3, 1





          share|improve this answer











          $endgroup$








          • 1




            $begingroup$
            Decided to go with this answer after all, since it is minimal, as all it does is a query -- no operations on the data.
            $endgroup$
            – Kagaratsch
            Mar 31 at 3:11


















          3












          $begingroup$

          Position[list, s_String /; ToLowerCase[s] == "abc"]



          3, 1




          or



          Position[list, s_String?(EqualTo["abc"]@*ToLowerCase)]





          share|improve this answer









          $endgroup$












          • $begingroup$
            I like how this does not need to make substitutions in list itself to search it!
            $endgroup$
            – Kagaratsch
            Mar 30 at 21:24






          • 2




            $begingroup$
            Position[ToLowerCase[list], "abc"] also works.
            $endgroup$
            – C. E.
            Mar 30 at 22:17











          • $begingroup$
            The rationale behind using a _String pattern is to pre-filter with a very inexpensive test: This ensures that only few expressions are actually fed to ToLowerCase.
            $endgroup$
            – Henrik Schumacher
            Mar 31 at 7:19


















          3












          $begingroup$

          Note that ToLowerCase does not evaluate if the input is not a string, but it is Listable, so it will thread over your list:



          list = 1.234, a[2], "Abc", 4/5, "acb";
          ToLowerCase[list]

          (* Out: ToLowerCase[1.234], ToLowerCase[a[2]], "abc", ToLowerCase[4/5], "acb" *)


          That should not bother you though; it certainly does not bother Position:



          Position[ToLowerCase[list], "abc"]
          (* Out: 3, 1 *)





          share|improve this answer









          $endgroup$













            Your Answer





            StackExchange.ifUsing("editor", function ()
            return StackExchange.using("mathjaxEditing", function ()
            StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
            StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
            );
            );
            , "mathjax-editing");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "387"
            ;
            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
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f194280%2ffind-non-case-sensitive-string-in-a-mixed-list-of-elements%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2












            $begingroup$

            Recall that StringMatchQ[] has the IgnoreCase option:



            Position[1.234, a[2], "Abc", 4/5, "acb",
            s_String /; StringMatchQ[s, "abc", IgnoreCase -> True]]
            3, 1





            share|improve this answer











            $endgroup$








            • 1




              $begingroup$
              Decided to go with this answer after all, since it is minimal, as all it does is a query -- no operations on the data.
              $endgroup$
              – Kagaratsch
              Mar 31 at 3:11















            2












            $begingroup$

            Recall that StringMatchQ[] has the IgnoreCase option:



            Position[1.234, a[2], "Abc", 4/5, "acb",
            s_String /; StringMatchQ[s, "abc", IgnoreCase -> True]]
            3, 1





            share|improve this answer











            $endgroup$








            • 1




              $begingroup$
              Decided to go with this answer after all, since it is minimal, as all it does is a query -- no operations on the data.
              $endgroup$
              – Kagaratsch
              Mar 31 at 3:11













            2












            2








            2





            $begingroup$

            Recall that StringMatchQ[] has the IgnoreCase option:



            Position[1.234, a[2], "Abc", 4/5, "acb",
            s_String /; StringMatchQ[s, "abc", IgnoreCase -> True]]
            3, 1





            share|improve this answer











            $endgroup$



            Recall that StringMatchQ[] has the IgnoreCase option:



            Position[1.234, a[2], "Abc", 4/5, "acb",
            s_String /; StringMatchQ[s, "abc", IgnoreCase -> True]]
            3, 1






            share|improve this answer














            share|improve this answer



            share|improve this answer








            answered Mar 31 at 0:03


























            community wiki





            J. M. is away








            • 1




              $begingroup$
              Decided to go with this answer after all, since it is minimal, as all it does is a query -- no operations on the data.
              $endgroup$
              – Kagaratsch
              Mar 31 at 3:11












            • 1




              $begingroup$
              Decided to go with this answer after all, since it is minimal, as all it does is a query -- no operations on the data.
              $endgroup$
              – Kagaratsch
              Mar 31 at 3:11







            1




            1




            $begingroup$
            Decided to go with this answer after all, since it is minimal, as all it does is a query -- no operations on the data.
            $endgroup$
            – Kagaratsch
            Mar 31 at 3:11




            $begingroup$
            Decided to go with this answer after all, since it is minimal, as all it does is a query -- no operations on the data.
            $endgroup$
            – Kagaratsch
            Mar 31 at 3:11











            3












            $begingroup$

            Position[list, s_String /; ToLowerCase[s] == "abc"]



            3, 1




            or



            Position[list, s_String?(EqualTo["abc"]@*ToLowerCase)]





            share|improve this answer









            $endgroup$












            • $begingroup$
              I like how this does not need to make substitutions in list itself to search it!
              $endgroup$
              – Kagaratsch
              Mar 30 at 21:24






            • 2




              $begingroup$
              Position[ToLowerCase[list], "abc"] also works.
              $endgroup$
              – C. E.
              Mar 30 at 22:17











            • $begingroup$
              The rationale behind using a _String pattern is to pre-filter with a very inexpensive test: This ensures that only few expressions are actually fed to ToLowerCase.
              $endgroup$
              – Henrik Schumacher
              Mar 31 at 7:19















            3












            $begingroup$

            Position[list, s_String /; ToLowerCase[s] == "abc"]



            3, 1




            or



            Position[list, s_String?(EqualTo["abc"]@*ToLowerCase)]





            share|improve this answer









            $endgroup$












            • $begingroup$
              I like how this does not need to make substitutions in list itself to search it!
              $endgroup$
              – Kagaratsch
              Mar 30 at 21:24






            • 2




              $begingroup$
              Position[ToLowerCase[list], "abc"] also works.
              $endgroup$
              – C. E.
              Mar 30 at 22:17











            • $begingroup$
              The rationale behind using a _String pattern is to pre-filter with a very inexpensive test: This ensures that only few expressions are actually fed to ToLowerCase.
              $endgroup$
              – Henrik Schumacher
              Mar 31 at 7:19













            3












            3








            3





            $begingroup$

            Position[list, s_String /; ToLowerCase[s] == "abc"]



            3, 1




            or



            Position[list, s_String?(EqualTo["abc"]@*ToLowerCase)]





            share|improve this answer









            $endgroup$



            Position[list, s_String /; ToLowerCase[s] == "abc"]



            3, 1




            or



            Position[list, s_String?(EqualTo["abc"]@*ToLowerCase)]






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 30 at 21:21









            Henrik SchumacherHenrik Schumacher

            59.9k582167




            59.9k582167











            • $begingroup$
              I like how this does not need to make substitutions in list itself to search it!
              $endgroup$
              – Kagaratsch
              Mar 30 at 21:24






            • 2




              $begingroup$
              Position[ToLowerCase[list], "abc"] also works.
              $endgroup$
              – C. E.
              Mar 30 at 22:17











            • $begingroup$
              The rationale behind using a _String pattern is to pre-filter with a very inexpensive test: This ensures that only few expressions are actually fed to ToLowerCase.
              $endgroup$
              – Henrik Schumacher
              Mar 31 at 7:19
















            • $begingroup$
              I like how this does not need to make substitutions in list itself to search it!
              $endgroup$
              – Kagaratsch
              Mar 30 at 21:24






            • 2




              $begingroup$
              Position[ToLowerCase[list], "abc"] also works.
              $endgroup$
              – C. E.
              Mar 30 at 22:17











            • $begingroup$
              The rationale behind using a _String pattern is to pre-filter with a very inexpensive test: This ensures that only few expressions are actually fed to ToLowerCase.
              $endgroup$
              – Henrik Schumacher
              Mar 31 at 7:19















            $begingroup$
            I like how this does not need to make substitutions in list itself to search it!
            $endgroup$
            – Kagaratsch
            Mar 30 at 21:24




            $begingroup$
            I like how this does not need to make substitutions in list itself to search it!
            $endgroup$
            – Kagaratsch
            Mar 30 at 21:24




            2




            2




            $begingroup$
            Position[ToLowerCase[list], "abc"] also works.
            $endgroup$
            – C. E.
            Mar 30 at 22:17





            $begingroup$
            Position[ToLowerCase[list], "abc"] also works.
            $endgroup$
            – C. E.
            Mar 30 at 22:17













            $begingroup$
            The rationale behind using a _String pattern is to pre-filter with a very inexpensive test: This ensures that only few expressions are actually fed to ToLowerCase.
            $endgroup$
            – Henrik Schumacher
            Mar 31 at 7:19




            $begingroup$
            The rationale behind using a _String pattern is to pre-filter with a very inexpensive test: This ensures that only few expressions are actually fed to ToLowerCase.
            $endgroup$
            – Henrik Schumacher
            Mar 31 at 7:19











            3












            $begingroup$

            Note that ToLowerCase does not evaluate if the input is not a string, but it is Listable, so it will thread over your list:



            list = 1.234, a[2], "Abc", 4/5, "acb";
            ToLowerCase[list]

            (* Out: ToLowerCase[1.234], ToLowerCase[a[2]], "abc", ToLowerCase[4/5], "acb" *)


            That should not bother you though; it certainly does not bother Position:



            Position[ToLowerCase[list], "abc"]
            (* Out: 3, 1 *)





            share|improve this answer









            $endgroup$

















              3












              $begingroup$

              Note that ToLowerCase does not evaluate if the input is not a string, but it is Listable, so it will thread over your list:



              list = 1.234, a[2], "Abc", 4/5, "acb";
              ToLowerCase[list]

              (* Out: ToLowerCase[1.234], ToLowerCase[a[2]], "abc", ToLowerCase[4/5], "acb" *)


              That should not bother you though; it certainly does not bother Position:



              Position[ToLowerCase[list], "abc"]
              (* Out: 3, 1 *)





              share|improve this answer









              $endgroup$















                3












                3








                3





                $begingroup$

                Note that ToLowerCase does not evaluate if the input is not a string, but it is Listable, so it will thread over your list:



                list = 1.234, a[2], "Abc", 4/5, "acb";
                ToLowerCase[list]

                (* Out: ToLowerCase[1.234], ToLowerCase[a[2]], "abc", ToLowerCase[4/5], "acb" *)


                That should not bother you though; it certainly does not bother Position:



                Position[ToLowerCase[list], "abc"]
                (* Out: 3, 1 *)





                share|improve this answer









                $endgroup$



                Note that ToLowerCase does not evaluate if the input is not a string, but it is Listable, so it will thread over your list:



                list = 1.234, a[2], "Abc", 4/5, "acb";
                ToLowerCase[list]

                (* Out: ToLowerCase[1.234], ToLowerCase[a[2]], "abc", ToLowerCase[4/5], "acb" *)


                That should not bother you though; it certainly does not bother Position:



                Position[ToLowerCase[list], "abc"]
                (* Out: 3, 1 *)






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 30 at 23:28









                MarcoBMarcoB

                38.7k557115




                38.7k557115



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Mathematica 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.

                    Use MathJax to format equations. MathJax reference.


                    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%2fmathematica.stackexchange.com%2fquestions%2f194280%2ffind-non-case-sensitive-string-in-a-mixed-list-of-elements%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

                    Triangular numbers and gcdProving sum of a set is $0 pmod n$ if $n$ is odd, or $fracn2 pmod n$ if $n$ is even?Is greatest common divisor of two numbers really their smallest linear combination?GCD, LCM RelationshipProve a set of nonnegative integers with greatest common divisor 1 and closed under addition has all but finite many nonnegative integers.all pairs of a and b in an equation containing gcdTriangular Numbers Modulo $k$ - Hit All Values?Understanding the Existence and Uniqueness of the GCDGCD and LCM with logical symbolsThe greatest common divisor of two positive integers less than 100 is equal to 3. Their least common multiple is twelve times one of the integers.Suppose that for all integers $x$, $x|a$ and $x|b$ if and only if $x|c$. Then $c = gcd(a,b)$Which is the gcd of 2 numbers which are multiplied and the result is 600000?

                    Ingelân Ynhâld Etymology | Geografy | Skiednis | Polityk en bestjoer | Ekonomy | Demografy | Kultuer | Klimaat | Sjoch ek | Keppelings om utens | Boarnen, noaten en referinsjes Navigaasjemenuwww.gov.ukOffisjele webside fan it regear fan it Feriene KeninkrykOffisjele webside fan it Britske FerkearsburoNederlânsktalige ynformaasje fan it Britske FerkearsburoOffisjele webside fan English Heritage, de organisaasje dy't him ynset foar it behâld fan it Ingelske kultuergoedYnwennertallen fan alle Britske stêden út 'e folkstelling fan 2011Notes en References, op dizze sideEngland

                    Հադիս Բովանդակություն Անվանում և նշանակություն | Դասակարգում | Աղբյուրներ | Նավարկման ցանկ