Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7632433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:37:28+00:00 2026-05-31T06:37:28+00:00

Suppose i have variable a with contents 123 and variable b123 with some text

  • 0

Suppose i have variable a with contents “123” and variable b123 with some text in it. For some reason i want to use variable a as part of second var name. Something like this:

SET a=123
SET b123=some_text_in_it
rem i want next line to output  "some_text_in_it"
echo %b%a%%

so i want to concatenate text with var contents and use resulting string as variable name to echo that contents. Sample above doesn’t work and i see why, probably i need to add some kind of groupping. How to do it, prefferably in one line?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T06:37:29+00:00Added an answer on May 31, 2026 at 6:37 am

    There are two common ways for this
    CALL or DelayedExpansion

    setlocal EnableDelayedExpansion
    SET a=123
    SET b123=some_text_in_it
    rem i want next line to output  "some_text_in_it"
    call echo %%b%a%%%
    echo !b%a%!
    

    The CALL variant uses the fact, that a call will reparse the line a second time, first time only the %a% will be expanded and the double %% will be reduced to a single %
    call echo %b123%
    And in the second step the %b123% will be expanded.
    But the CALL technic is slow and not very safe, so the DelayedExpansion should be prefered.

    The DelayedExpansion works as the exclamation marks are expanded in a later parser phase than the expansion of the percents.
    And that’s also the cause, why delayed expansion is much safer.

    Edit: Method for arrays containing numbers
    If you are operating with arrays which contains only numbers you could also use set /a to access them.
    That’s much easier than the FOR or CALL technic and it works also in blocks.

    setlocal EnableDelayedExpansion
    set arr[1]=17
    set arr[2]=35
    set arr[3]=77
    (
      set idx=2
      set /a val=arr[!idx!]
      echo !var!
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Java, suppose I have a String variable S, and I want to search
Suppose I have two classes that both contain a static variable, XmlTag. The second
Suppose I have a class Foo , with a private variable bar_ containing some
Let's suppose I have n arrays, where n is a variable (some number greater
Suppose I have some text files (f1.txt, f2.txt, ...) that looks something like @article
I have a Big html in String variable and I want to get contents
Suppose I have a variable of type Int = 08, how can I convert
Suppose i have a LPSTR variable. How do i free the memory after using
Suppose I have a static variable declared inside a function in C. If I
Suppose that I have an integer variable in a class, and this variable may

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.