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

  • Home
  • SEARCH
  • 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 850811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:19:37+00:00 2026-05-15T07:19:37+00:00

If I have the following code: var value : String = StringUtil.substitute(The value {0}

  • 0

If I have the following code:

var value : String = StringUtil.substitute("The value {0} requested is {1}", user, value);

How can I use the variable name instead of using {0} and {1} in the code.

Please advice. Thanks.

Edit:

The above code is quoted from http://www.rialvalue.com/blog/2010/05/10/string-templating-in-flex/.
It says that “Also note that we’re substituting the parameters using the order, it’d would fairly easy to do a named-parameter subsitution instead (i.e. using tokens like ${var1})”. Therefore, I think it may be very easy to do that, but I don’t know how to do.

  • 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-15T07:19:38+00:00Added an answer on May 15, 2026 at 7:19 am

    Looks like it’s not possible. And kind of makes sense that it allows zero based ints only, since you’re passing a variable number of parameters that you’re not identifying (except for their relative position in the params list).

    Here’s a piece of code that will replace tokens by name:

        public static function replacePlaceholders(input:String,replacementMap:Object):String {
            // '${', followed by any char except '}', ended by '}'
            return input.replace(/\${([^}]*)}/g,function():String {
                return replaceEntities(arguments,replacementMap);
            });
    
        }
    
        private static function replaceEntities(regExpArgs:Array,map:Object):String {
            var entity:String       = String(regExpArgs[0]);
            var entityBody:String   = String(regExpArgs[1]);
            return (map[entityBody]) ? map[entityBody] : entity;
        }
    

    Use:

    var test:String = "Hello there ${name}, how is the ${noun} today?";
    var replacementMap:Object   = { 
        name    :   "YOUR_NAME_HERE",
        noun    :   "YOUR_NOUN_HERE"
    };
    
    trace(StringUtils.replacePlaceholders(test,replacementMap));
    

    The format I’m using for the placeholders is ${placeholdername}, since it’s safer, I think. But if you want to remove the dollar sign, change the regexp accordingly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: var bool:String = true; Without an if block or
I have the following code var query = from lookup in dataset.Tables[MBDDX_LOOKUP].AsEnumerable() where lookup.Field<string>(lookup_value)
I have the following code: class Parameterizable{ var map: Map[String, String] = new scala.collection.immutable.HashMap()
I have the following code: var redirectIp = string.Format({0}{1}, Session[CurrentHost], ip.PathAndQuery); return new RedirectResult(redirectIp);
using jQuery I have the following code: var selectedIdsArray = $(#selectId option:selected).map(function(){return this.value;}); var
I have the following code var email = document.getElementById(email).value; $.post(/valid,{emailadd: email},function(data){ alert(data); }); on
Can anyone save me? I have the following code: private List<string> GenerateTerms(string[] docs) {
I have the following code to populate a DropDownList var list = new Dictionary<string,
I have the following code: public IEnumerable<Content.Grid> DetailsBase(string pk) { var data = contentRepository.GetPk(pk);
I have the following code: var submitHandler = function ($link, $form, close) { var

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.