• Login
sketchucation logo sketchucation
  • Login
ℹ️ GoFundMe | Our friend Gus Robatto needs some help in a challenging time Learn More

Search a DC attribute string value

Scheduled Pinned Locked Moved Dynamic Components
sketchup
5 Posts 2 Posters 7.5k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    hank
    last edited by 20 Jun 2017, 02:38

    If you wanted to see if the string "Hello" was in the following attribute string value...

    qwertyHello12345

    How would you do it?

    The trick is, can you return one value (like "TRUE" or "1") if found and another (like "FALSE" or "0") if not?

    I would be interested in a Ruby solution too if necessary!

    1 Reply Last reply Reply Quote 0
    • P Offline
      pcmoor
      last edited by 21 Jun 2017, 03:25

      Add the required text to the end of the string then use "find", then compare the length of the original string and position returned by find. By adding your text to the end, find will always return a value


      test string.skp

      1 Reply Last reply Reply Quote 0
      • H Offline
        hank
        last edited by 22 Jun 2017, 13:20

        Thanks pcmoor.

        So... trying to understand this. You have:

        =if((find("hello",Astring&"hello",1)-len(Astring))<0,"true","false")
        

        where Astrin is set to

        hellggggheloxxhell
        

        So in other words

        =if((find("hello","hellggggheloxxhell"&"hello",1)-len("hellggggheloxxhell"))<0,"true","false")
        

        Which I think means:
        If FIND returns a number that is greater than the length of the search string, return true.

        So you are sort of forcing FIND to return something if the search string is not found by a certain position by adding the search string onto the end of the search haysatck,right?

        I'm not sure I understand completely but this seems like some ninja stuff!

        1 Reply Last reply Reply Quote 0
        • P Offline
          pcmoor
          last edited by 22 Jun 2017, 23:19

          More or less correct. As you know find returns a position but that is -1 (an error) if there is no instance of the required text. So adding the text you are trying to find to the end of the original string, then if there is no other instance, then position return will not be -1 but the length of the original string plus one,
          So the difference between (position-len(original string)) returns a negative number if another instance is found, which if<0 will return true

          added the above example with extra attributes to show steps clearer. but better to use one liners to save space in your DC dialog, once understood


          separated fields

          1 Reply Last reply Reply Quote 0
          • H Offline
            hank
            last edited by 24 Jun 2017, 14:56

            YES! I see now. That is some pretty sweet re-engineering of the pretty remedial string functions! I do wish FIND would just return FALSE if the string is not found but oh well. Thanks Again pcmoor!

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            1 / 1
            • First post
              1/5
              Last post
            Buy SketchPlus
            Buy SUbD
            Buy WrapR
            Buy eBook
            Buy Modelur
            Buy Vertex Tools
            Buy SketchCuisine
            Buy FormFonts

            Advertisement