Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: set command escape character  (Read 8442 times)

0 Members and 1 Guest are viewing this topic.

John_L.

    Topic Starter


    Rookie

    Thanked: 2
    • Experience: Experienced
    • OS: Windows XP
    set command escape character
    « on: February 11, 2021, 04:11:29 PM »
    I've got the contents of a batch variable and I'd like to change "~" to "&#7E;" (without the quotes). I thought this would work:

    set J=blah~blah
    set J=%J:~=^&#7E;%

    but alas, it does not.

    Thanks in advance for any insight you can provide.

    DaveLembke



      Sage
    • Thanked: 662
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: set command escape character
    « Reply #1 on: February 11, 2021, 09:23:32 PM »
    Thinking you might need to set variable as a string as the escape character only escapes the first single character of & and the rest is unexpected syntax. More at this link on the SET command.

    https://ss64.com/nt/set.html

    John_L.

      Topic Starter


      Rookie

      Thanked: 2
      • Experience: Experienced
      • OS: Windows XP
      Re: set command escape character
      « Reply #2 on: February 12, 2021, 09:13:14 AM »
      Thanks much.

      The 8191 character limit for environment variables will likely bite me in the future, any experience with workarounds? I know of a DOS-based sed, and I "could" write a very small Java program...I prefer to keep it simple, and reduce dependancies (as if .bat files are "simple")

      Thanks again.

      DaveLembke



        Sage
      • Thanked: 662
      • Certifications: List
      • Computer: Specs
      • Experience: Expert
      • OS: Windows 10
      Re: set command escape character
      « Reply #3 on: February 18, 2021, 09:12:06 AM »
      Curious if there is a need to use batch at all in what your trying to achieve? I have used system calls to DOS environment from within programs that aren't in the root of the system, so for example with C++ and PERL I have used system calls and these languages allow for far more than Batch Files themselves.  *System Calls from C++ etc, some see as poor programming practice though, but they work. They are ok for applications where you yourself are using them and others dont interact with them.

      SED is good, but I have used mostly PERL for making batched like scripts do what I want and without the limits of batch itself.

      Squashman



        Specialist
      • Thanked: 134
      • Experience: Experienced
      • OS: Other
      Re: set command escape character
      « Reply #4 on: March 26, 2021, 01:03:53 PM »
      The problem is the tilde.  If you read the help file for the SET command you will notice that the tilde and equals symbol both have special meanings.  The tilde is used for substrings and the equals symbol is used for string replacement.  You cannot escape the tilde or equals symbol in the SET command which means you cannot do string replacement on either symbol with the SET command.