Duet3D Logo Duet3D
    • Tags
    • Documentation
    • Order
    • Register
    • Login

    String handling functions

    Scheduled Pinned Locked Moved
    Firmware wishlist
    2
    4
    262
    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.
    • OwenDundefined
      OwenD
      last edited by OwenD

      I realise that there's probably bigger fish to fry at the moment, but this is a wish list section and I feel this would greatly extend conditional g code functionality.

      I'd like to see a few string handling routines built into RRF.
      Each on their own bay have limited use, but together become quite powerful.
      They would all be recognised as available in most programming languages though the syntax would differ.

      These would be

      length("string") - return the length of a string
      e.g. length(0:/sys/config.g) = 14

      pos("pattern","string") - return the index of the first occurrence of a substring within a string.
      Return -1 if not found

      e.g pos(".","0:/sys/config.g") = 12 (zero based)

      copy("string",index,"nnn") - return a substring containing "nnn" characters starting at index (zero based)

      e.g. copy("my_string",3,3) = "str"

      leftStr("string",nnn) - return a string of "nnn" length starting at the first character
      e.g. left("my_string",4) = "my_s"

      rightStr("string",nnn) - same as above but return the last "nnn" characters

      strReplace("substring","new string", "string",replaceParams) - replaces occurrences of a substring with another.
      Parameters to replace all, and ignore case.

      e.g. strReplace("P6","B7","z2P6p6macro.g"[replaceAll,IgnoreCase] = "z2B7B7macro.g"
      or by changing parameters it could also be
      z2B7p6macro.g

      upperCase("string") - return a string in all caps
      e.g upperCase("myString") = "MYSTRING"

      lowerCase("string") - same except return all lowercase

      zaptaundefined 1 Reply Last reply Reply Quote 2
      • zaptaundefined
        zapta @OwenD
        last edited by

        @owend said in String handling functions:

        lowerCase("string") - same except return all lowercase

        Any use cases?

        Yes, I know, it's a common push back technique. 😉

        OwenDundefined 1 Reply Last reply Reply Quote 0
        • OwenDundefined
          OwenD @zapta
          last edited by

          @zapta
          Most of the use cases I've had would be for making code more portable through not hard coding things.
          It's been a case of doing something and thinking if I could just extract that part of the string, or change it to that, then I could do it this way.
          In each case I've just moved on and done what I had to do within the existing framework.
          As I said, each on their own they're less powerful.

          zaptaundefined 1 Reply Last reply Reply Quote 1
          • zaptaundefined
            zapta @OwenD
            last edited by

            @owend, it may be helpful in the use case below, splinting the terms and converting them to numbers

            https://forum.duet3d.com/topic/27201/macro-parameter-letters

            1 Reply Last reply Reply Quote 0
            • First post
              Last post
            Unless otherwise noted, all forum content is licensed under CC-BY-SA