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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:04:10+00:00 2026-06-02T13:04:10+00:00

I want to do something in ColdFusion that is similar to sprintf in C

  • 0

I want to do something in ColdFusion that is similar to sprintf in C or Perl. I found this
answer, which seems to be what I’m looking for. However, I can’t get it to work.

Here is what I’m trying:

<cftry>
    <cfset firstName="John">
    <cfset output=createObject("java","java.lang.String").format("Hello, %s!", firstName)>
    <cfcatch type="any">
        <cfdump var="#cfcatch#" expand="false">
    </cfcatch>
<cftry>

And here is what I get:

cfcatch.Message: The format method was not found.

cfcatch.Detail: Either there are no methods with the specified method
name and argument types or the format method is overloaded with
argument types that ColdFusion cannot decipher reliably. ColdFusion
found 0 methods that match the provided arguments. If this is a Java
object and you verified that the method exists, use the javacast
function to reduce ambiguity.

This is an overloaded method, so I did as suggested and used JavaCast on the arguments:

<cfset output=createObject("java","java.lang.String").format(JavaCast('string', "Hello, %s!"), firstName)>
<cfset output=createObject("java","java.lang.String").format("Hello, %s!", JavaCast('string', firstName))>
<cfset output=createObject("java","java.lang.String").format(JavaCast('string', "Hello, %s!"), JavaCast('string', firstName))>

and got the same error every time.

I tried another static method on the String class, valueOf, and it worked fine.

Edit:
I’ve already seen a comment, and I’m not sure how to respond to those, but maybe I should explain here. What I’ve shown above is an extremely simplified example of what I am trying to do. The goal is to use a format string to provide lots of formatting in one place, and then simply pass in a list of variables, instead of formatting a bunch of variables and outputting them, or formatting them as I’m outputting them. With the format method, I plan to build a set of format strings that match the output I need, then I will just cfloop or cfoutput over a query, run this one method inside, and get the output I want. No DateFormat, NumberFormat, Left, Right, etc. If I can’t get this working, that is plan B though.

I’m running ColdFusion 9.01, Windows 7, Java 1.6.0_22.

Any and all help is greatly appreciated.

  • 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-06-02T13:04:11+00:00Added an answer on June 2, 2026 at 1:04 pm

    Answer based on my comment above:

    It probably can’t match the format method you’re looking for because its signature is format(String, Object[]) and your second String argument can’t be automatically converted to an Object array.

    You could change the argument to encapsulate the name in an array as follows: format("Hello, %s!", [firstName]).

    Thanks to Leigh for being so courteous, I upvoted your comments 🙂

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

Sidebar

Related Questions

I want to implement something like autocomplete feature like this: http://jqueryui.com/demos/autocomplete/ However I cannot
I want something like the following: foo.should_receive(:bar).with(an_instance_of(Bla))..... Is this possible? Edit: According to the
I want something that will receive me the processes details, like I receive with
I want something to put in my .htaccess file that will hide the .php
I want something like this: abcdab.search(/a/g) //return [0,4] Is it possible?
:bn , :bp just switches buffers I want something like ctrl-o, which has a
I often want to write something like this: new Form { Text = Caption,
this is something I have always had confusion about I never can seem to
This is probably something silly and simple in vectors or something, but I can't
I want something like the following but would like it to be reusable for

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.