How do I use an if statement to check if a certain string of text is in another set of characters?How to set default values for Tcl variables?TCL: regexp exclude strings having charactersTCL string toupper (each word)Delete line regex is found onHow to force expr to address a value as a string and not a number?how to set text indices via a variableReading specific column of data from text file and write to another text file tclTcl/tk - Get window height and width and set relative text height in gridHow to append to array at certain keyTo match and extract multiple words from directory path using tcl

What is more environmentally friendly? An A320 or a car?

Is there a wealth gap in Boston where the median net worth of white households is $247,500 while the median net worth for black families was $8?

Do the books ever say oliphaunts aren’t elephants?

What happens when a flying sword is killed?

Does Dispel Magic destroy Artificer Turrets?

reconstruction filter - How does it actually work?

How does one get an animal off of the Altar surreptitiously?

Is there an antonym(a complementary antonym) for "spicy" or "hot" regarding food (I DO NOT mean "seasoned" but "hot")?

Why is の所 used after ドア in this sentence?

Compound Word Neologism

Spacing after a tikz figure

Why would anyone ever invest in a cash-only etf?

Examples of simultaneous independent breakthroughs

Japanese reading of an integer

Why does Canada require mandatory bilingualism in a lot of federal government posts?

Polyhedra, Polyhedron, Polytopes and Polygon

Incrementing add under condition in pandas

Does dual boot harm a laptop battery or reduce its life?

Why didn’t Christianity spread southwards from Ethiopia in the Middle Ages?

How likely is fragmentation on a table with 40000 products likely to affect performance

How did the Sinclair compare on price with the C64 in the UK?

Is it safe if the neutral lead is exposed and disconnected?

Why does the Eurostar not show youth pricing?

8086 stack segment and avoiding overflow in interrupts



How do I use an if statement to check if a certain string of text is in another set of characters?


How to set default values for Tcl variables?TCL: regexp exclude strings having charactersTCL string toupper (each word)Delete line regex is found onHow to force expr to address a value as a string and not a number?how to set text indices via a variableReading specific column of data from text file and write to another text file tclTcl/tk - Get window height and width and set relative text height in gridHow to append to array at certain keyTo match and extract multiple words from directory path using tcl






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I want to make an if statement that will return a value when a certain characters are in another set of texts. For example if I have the words water, and fire. I want to make an if statement that will check if the word I give it has characters "wa" then it will return a value of 1. Something along the lines of this.



set word "water"
set tempvar 0
if $word has characters "wa"
set tempvar 1










share|improve this question
































    0















    I want to make an if statement that will return a value when a certain characters are in another set of texts. For example if I have the words water, and fire. I want to make an if statement that will check if the word I give it has characters "wa" then it will return a value of 1. Something along the lines of this.



    set word "water"
    set tempvar 0
    if $word has characters "wa"
    set tempvar 1










    share|improve this question




























      0












      0








      0








      I want to make an if statement that will return a value when a certain characters are in another set of texts. For example if I have the words water, and fire. I want to make an if statement that will check if the word I give it has characters "wa" then it will return a value of 1. Something along the lines of this.



      set word "water"
      set tempvar 0
      if $word has characters "wa"
      set tempvar 1










      share|improve this question
















      I want to make an if statement that will return a value when a certain characters are in another set of texts. For example if I have the words water, and fire. I want to make an if statement that will check if the word I give it has characters "wa" then it will return a value of 1. Something along the lines of this.



      set word "water"
      set tempvar 0
      if $word has characters "wa"
      set tempvar 1







      tcl






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 26 at 19:42









      Donal Fellows

      106k15 gold badges118 silver badges182 bronze badges




      106k15 gold badges118 silver badges182 bronze badges










      asked Mar 26 at 19:31









      MakuzaMakuza

      1




      1

























          3 Answers
          3






          active

          oldest

          votes


















          2














          The simplest (and fastest!) way to search for whether a substring is present is the string first command; that returns -1 if the substring isn't there, and the (first) index of where it is found when the substring is present.



          if [string first "wa" $word] >= 0 
          set tempvar 1



          The other technique that works well is one of the lesser known operating modes of Tcl's regular expression engine: if the RE starts with ***= then the rest of the string is a literal.



          # This is marginally slower than string first; the overhead of the RE engine matters a little
          if [regexp ***=wa $word]
          set tempvar 1



          Note that if you were asking if it was a prefix, other commands are more suitable (string equal with the -length option, or string match). And use lsearch if you want to know if a particular value is an element in a list, instead of string searching.






          share|improve this answer

























          • The reason you have to be a little careful is that a lot of the more sophisticated matchers have important metacharacters. It doesn't matter when looking for wa, but if you're looking for wa or *wa* it can matter a lot. A little care at the beginning makes life much easier later on.

            – Donal Fellows
            Mar 29 at 9:38


















          1














          I would encapsulate this in a proc:



          proc string_contains haystack needle 
          expr [string first $needle $haystack] != -1



          then



          % string_contains water wa
          1
          % string_contains fire wa
          0


          and



          % if [string_contains water wa] then puts yes else puts no
          yes
          % if [string_contains fire wa] then puts yes else puts no
          no





          share|improve this answer

























          • One has to be careful about the empty string as needle then, string first is just broken in this respect: string_contains water "" will give 0.

            – mrcalvin
            Mar 28 at 23:36


















          0














          Generally, in any language, for matching purpose, Regular Expressions are used, here used as regexp $pattern $string and return 1 if there is a match.



          set word "water" 
          set tempvar 0
          if [regexp "wa" $word]
          set tempvar 1

          puts $tempvar





          share|improve this answer



























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            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: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            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%2fstackoverflow.com%2fquestions%2f55364952%2fhow-do-i-use-an-if-statement-to-check-if-a-certain-string-of-text-is-in-another%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














            The simplest (and fastest!) way to search for whether a substring is present is the string first command; that returns -1 if the substring isn't there, and the (first) index of where it is found when the substring is present.



            if [string first "wa" $word] >= 0 
            set tempvar 1



            The other technique that works well is one of the lesser known operating modes of Tcl's regular expression engine: if the RE starts with ***= then the rest of the string is a literal.



            # This is marginally slower than string first; the overhead of the RE engine matters a little
            if [regexp ***=wa $word]
            set tempvar 1



            Note that if you were asking if it was a prefix, other commands are more suitable (string equal with the -length option, or string match). And use lsearch if you want to know if a particular value is an element in a list, instead of string searching.






            share|improve this answer

























            • The reason you have to be a little careful is that a lot of the more sophisticated matchers have important metacharacters. It doesn't matter when looking for wa, but if you're looking for wa or *wa* it can matter a lot. A little care at the beginning makes life much easier later on.

              – Donal Fellows
              Mar 29 at 9:38















            2














            The simplest (and fastest!) way to search for whether a substring is present is the string first command; that returns -1 if the substring isn't there, and the (first) index of where it is found when the substring is present.



            if [string first "wa" $word] >= 0 
            set tempvar 1



            The other technique that works well is one of the lesser known operating modes of Tcl's regular expression engine: if the RE starts with ***= then the rest of the string is a literal.



            # This is marginally slower than string first; the overhead of the RE engine matters a little
            if [regexp ***=wa $word]
            set tempvar 1



            Note that if you were asking if it was a prefix, other commands are more suitable (string equal with the -length option, or string match). And use lsearch if you want to know if a particular value is an element in a list, instead of string searching.






            share|improve this answer

























            • The reason you have to be a little careful is that a lot of the more sophisticated matchers have important metacharacters. It doesn't matter when looking for wa, but if you're looking for wa or *wa* it can matter a lot. A little care at the beginning makes life much easier later on.

              – Donal Fellows
              Mar 29 at 9:38













            2












            2








            2







            The simplest (and fastest!) way to search for whether a substring is present is the string first command; that returns -1 if the substring isn't there, and the (first) index of where it is found when the substring is present.



            if [string first "wa" $word] >= 0 
            set tempvar 1



            The other technique that works well is one of the lesser known operating modes of Tcl's regular expression engine: if the RE starts with ***= then the rest of the string is a literal.



            # This is marginally slower than string first; the overhead of the RE engine matters a little
            if [regexp ***=wa $word]
            set tempvar 1



            Note that if you were asking if it was a prefix, other commands are more suitable (string equal with the -length option, or string match). And use lsearch if you want to know if a particular value is an element in a list, instead of string searching.






            share|improve this answer













            The simplest (and fastest!) way to search for whether a substring is present is the string first command; that returns -1 if the substring isn't there, and the (first) index of where it is found when the substring is present.



            if [string first "wa" $word] >= 0 
            set tempvar 1



            The other technique that works well is one of the lesser known operating modes of Tcl's regular expression engine: if the RE starts with ***= then the rest of the string is a literal.



            # This is marginally slower than string first; the overhead of the RE engine matters a little
            if [regexp ***=wa $word]
            set tempvar 1



            Note that if you were asking if it was a prefix, other commands are more suitable (string equal with the -length option, or string match). And use lsearch if you want to know if a particular value is an element in a list, instead of string searching.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 26 at 19:49









            Donal FellowsDonal Fellows

            106k15 gold badges118 silver badges182 bronze badges




            106k15 gold badges118 silver badges182 bronze badges















            • The reason you have to be a little careful is that a lot of the more sophisticated matchers have important metacharacters. It doesn't matter when looking for wa, but if you're looking for wa or *wa* it can matter a lot. A little care at the beginning makes life much easier later on.

              – Donal Fellows
              Mar 29 at 9:38

















            • The reason you have to be a little careful is that a lot of the more sophisticated matchers have important metacharacters. It doesn't matter when looking for wa, but if you're looking for wa or *wa* it can matter a lot. A little care at the beginning makes life much easier later on.

              – Donal Fellows
              Mar 29 at 9:38
















            The reason you have to be a little careful is that a lot of the more sophisticated matchers have important metacharacters. It doesn't matter when looking for wa, but if you're looking for wa or *wa* it can matter a lot. A little care at the beginning makes life much easier later on.

            – Donal Fellows
            Mar 29 at 9:38





            The reason you have to be a little careful is that a lot of the more sophisticated matchers have important metacharacters. It doesn't matter when looking for wa, but if you're looking for wa or *wa* it can matter a lot. A little care at the beginning makes life much easier later on.

            – Donal Fellows
            Mar 29 at 9:38













            1














            I would encapsulate this in a proc:



            proc string_contains haystack needle 
            expr [string first $needle $haystack] != -1



            then



            % string_contains water wa
            1
            % string_contains fire wa
            0


            and



            % if [string_contains water wa] then puts yes else puts no
            yes
            % if [string_contains fire wa] then puts yes else puts no
            no





            share|improve this answer

























            • One has to be careful about the empty string as needle then, string first is just broken in this respect: string_contains water "" will give 0.

              – mrcalvin
              Mar 28 at 23:36















            1














            I would encapsulate this in a proc:



            proc string_contains haystack needle 
            expr [string first $needle $haystack] != -1



            then



            % string_contains water wa
            1
            % string_contains fire wa
            0


            and



            % if [string_contains water wa] then puts yes else puts no
            yes
            % if [string_contains fire wa] then puts yes else puts no
            no





            share|improve this answer

























            • One has to be careful about the empty string as needle then, string first is just broken in this respect: string_contains water "" will give 0.

              – mrcalvin
              Mar 28 at 23:36













            1












            1








            1







            I would encapsulate this in a proc:



            proc string_contains haystack needle 
            expr [string first $needle $haystack] != -1



            then



            % string_contains water wa
            1
            % string_contains fire wa
            0


            and



            % if [string_contains water wa] then puts yes else puts no
            yes
            % if [string_contains fire wa] then puts yes else puts no
            no





            share|improve this answer













            I would encapsulate this in a proc:



            proc string_contains haystack needle 
            expr [string first $needle $haystack] != -1



            then



            % string_contains water wa
            1
            % string_contains fire wa
            0


            and



            % if [string_contains water wa] then puts yes else puts no
            yes
            % if [string_contains fire wa] then puts yes else puts no
            no






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 26 at 22:02









            glenn jackmanglenn jackman

            177k26 gold badges155 silver badges251 bronze badges




            177k26 gold badges155 silver badges251 bronze badges















            • One has to be careful about the empty string as needle then, string first is just broken in this respect: string_contains water "" will give 0.

              – mrcalvin
              Mar 28 at 23:36

















            • One has to be careful about the empty string as needle then, string first is just broken in this respect: string_contains water "" will give 0.

              – mrcalvin
              Mar 28 at 23:36
















            One has to be careful about the empty string as needle then, string first is just broken in this respect: string_contains water "" will give 0.

            – mrcalvin
            Mar 28 at 23:36





            One has to be careful about the empty string as needle then, string first is just broken in this respect: string_contains water "" will give 0.

            – mrcalvin
            Mar 28 at 23:36











            0














            Generally, in any language, for matching purpose, Regular Expressions are used, here used as regexp $pattern $string and return 1 if there is a match.



            set word "water" 
            set tempvar 0
            if [regexp "wa" $word]
            set tempvar 1

            puts $tempvar





            share|improve this answer





























              0














              Generally, in any language, for matching purpose, Regular Expressions are used, here used as regexp $pattern $string and return 1 if there is a match.



              set word "water" 
              set tempvar 0
              if [regexp "wa" $word]
              set tempvar 1

              puts $tempvar





              share|improve this answer



























                0












                0








                0







                Generally, in any language, for matching purpose, Regular Expressions are used, here used as regexp $pattern $string and return 1 if there is a match.



                set word "water" 
                set tempvar 0
                if [regexp "wa" $word]
                set tempvar 1

                puts $tempvar





                share|improve this answer













                Generally, in any language, for matching purpose, Regular Expressions are used, here used as regexp $pattern $string and return 1 if there is a match.



                set word "water" 
                set tempvar 0
                if [regexp "wa" $word]
                set tempvar 1

                puts $tempvar






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 31 at 4:56









                DrektzDrektz

                348 bronze badges




                348 bronze badges






























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • 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%2fstackoverflow.com%2fquestions%2f55364952%2fhow-do-i-use-an-if-statement-to-check-if-a-certain-string-of-text-is-in-another%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

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                    Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript