Loading ...
Sorry, an error occurred while loading the content.

Grabbing first 4 characters from a variable

Expand Messages
  • J
    My batch-fu is pretty weak, so I ask you who are masters. I have a variable that is up to 15 characters long, I just want to be able to grab the first 4
    Message 1 of 3 , Apr 15 8:33 PM
    • 0 Attachment
      My batch-fu is pretty weak, so I ask you who are masters. I have a variable that is up to 15 characters long, I just want to be able to grab the first 4 characters and pipe them into a new variable. Any help?

      Thanks in advance.

      --> J
    • Parag P. Doke
      My attempt: set MyVar1=ABCDEFGHIJKLMNOset MyVar2=%MyVar1:~0,4% echo %MyVar2% See the output of set /? for reference. Regards, Parag P. Doke
      Message 2 of 3 , Apr 15 10:03 PM
      • 0 Attachment
        My attempt:

        set MyVar1=ABCDEFGHIJKLMNOset MyVar2=%MyVar1:~0,4%
        echo %MyVar2%

        See the output of "set /?" for reference.

        Regards,
        Parag P. Doke
        http://paragpdoke.blogspot.com
        Save paper, save trees. Do not print emails/documents unless absolutely
        necessary.



        On Thu, Apr 16, 2009 at 9:03 AM, J <grail_pbem@...> wrote:

        >
        >
        > My batch-fu is pretty weak, so I ask you who are masters. I have a variable
        > that is up to 15 characters long, I just want to be able to grab the first 4
        > characters and pipe them into a new variable. Any help?
        >
        > Thanks in advance.
        >
        > --> J
        >
        >
        >


        [Non-text portions of this message have been removed]
      • J
        Thanks muchly, and also to those who replied privately. set MyVar2=%MyVar1:~0,4% worked fine. -- J
        Message 3 of 3 , Apr 16 3:20 PM
        • 0 Attachment
          Thanks muchly, and also to those who replied privately.

          set MyVar2=%MyVar1:~0,4%
          worked fine.
          --> J

          >
          > My attempt:
          >
          > set MyVar1=ABCDEFGHIJKLMNOset MyVar2=%MyVar1:~0,4%
          > echo %MyVar2%
          >
          > See the output of "set /?" for reference.
          >
          > Regards,
          > Parag P. Doke
          > http://paragpdoke.blogspot.com
          > Save paper, save trees. Do not print emails/documents unless absolutely
          > necessary.
          >
          >
          >
          > On Thu, Apr 16, 2009 at 9:03 AM, J <grail_pbem@...> wrote:
          >
          > >
          > >
          > > My batch-fu is pretty weak, so I ask you who are masters. I have a variable
          > > that is up to 15 characters long, I just want to be able to grab the first 4
          > > characters and pipe them into a new variable. Any help?
          > >
          > > Thanks in advance.
          > >
          > > --> J
          > >
          > >
          > >
          >
          >
          > [Non-text portions of this message have been removed]
          >
        Your message has been successfully submitted and would be delivered to recipients shortly.