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 591249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:36:54+00:00 2026-05-13T15:36:54+00:00

I have a format method that works in a similar manner to the C#

  • 0

I have a “format” method that works in a similar manner to the C# String.Format method, with the following signature:

In a class named StringTools:

/**
 * Formats a string, based on C# String.Format method.
 * @param raw A string with numbered tokens, such as "{0}, {1}"
 * @param rest Values that replace the numbered tokens in raw.
 */
public static function format(raw:String, ...rest:*):String;

StringTools.format(“{0}, {1}”, “Hello”, “World”) returns the string “Hello, World” as expected. Now, I’m trying to get my logging class to use this method, but I’m having trouble passing the optional variables through. The signature of the method in the logging class is:

public static function infof(raw:String, ...rest:*):String;

If I pass “rest” directly into StringTools.format(raw, rest), it’s passed in as an array, and not as a series of parameters, so if I call it liks this: infof(“{0}, {1}”, “Hello”, “World”), I get the string “Hello,World, {1}”, since it replaces the first token with the entire array of values.

I also tried constructing an arguments array, and calling the method like this:

var collectArgs:Array = [raw];

for (var i:Number = 0; i < rest.length; i++)
{
collectArgs.push(rest[i]);
}

var callFunction:Function = StringTools.format.call;

trace(callFunction.apply(null, collectArgs));

However, this traces “World,6”. So, it looks like the parameters are shifted. So, I tried initializing collectArgs as [null, raw], and I get “Hello World,6. The number is {1}” again.

Am I doing something wrong? What is the correct way to pass optional parameters from one method that expects optional parameters to another method that expects optional parameters?

Thanks!

  • 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-13T15:36:54+00:00Added an answer on May 13, 2026 at 3:36 pm

    I think you are on the right lines using apply. This seems to do illustrate the behaviour you want:

    static function f1(raw:String, ...rest:*):void
    {
        trace("f1: "+raw+" "+rest);
        rest.unshift(raw);
        f2.apply(null, rest); 
    }
    
    static function f2(raw:String, ...rest:*):void
    {
        trace("f2: "+raw+" "+rest);
    }
    
    function passSomeArguments():void
    {
        f1("A",1,2,3);
    }
    

    EDIT: You need to pass ‘null’ as the 1st parameter to apply because the first parameter is what is considered to be ‘this’ when the function is called. Since the functions are static (and in any case have no dependency on ‘this’) you can pass null, but you must pass something.

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

Sidebar

Related Questions

Hey, I currently have a Currency Format method: private string FormatCurrency(double moneyIn) { CultureInfo
I want to match dates that have the following format: 2010-08-27, 2010/08/27 Right now
I have the following code that works: @for (var index = 0; index <
I have a Date format: 2009-08-10T16:03:03Z that I want to convert to: @MMM dd,
We currently have a specific format for how our email addresses are defined, based
i have that method that retrieve the removable devices information which are NTFS :
I have a simple WebService method that returns database results as a DataSet. This
I have a form that works, but I need to have some fields hidden
In my MVC 2 application I have a typical method that calls a web
I want my report pages to have A4 format. to do this i used

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.