String.format()

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

String.format()

Adam Sherman
String.format() under Java 1.5 seems to use a rather peculier syntax
with a variable number of arguments. Is it possible to call this
method from a bsh script?

Thanks,

A.

--
Adam Sherman
Technologist


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
<a href="http://ads.osdn.com/?ad_idv37&alloc_id865&op=click">http://ads.osdn.com/?ad_idv37&alloc_id865&op=click
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|

Re: String.format()

Daniel Wunsch
On Wednesday 30 November 2005 20:39, Adam Sherman wrote:
> String.format() under Java 1.5 seems to use a rather peculier syntax
> with a variable number of arguments. Is it possible to call this
> method from a bsh script?

try something like this:
"some string".format(format, new Object[] { arg1, arg2, arg3 });

daniel


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|

Re: String.format()

james.m.kortge
In reply to this post by Adam Sherman
(Okay, Daniel beat me to it...)


Under the covers, format(String format, Object... args) is really
format(String format, Object[] args).

bsh % print(String.format("local time is %tT", new Object[]
{Calendar.getInstance()}));
local time is 15:21:49

I think there are plans to add varargs to the BeanShell syntax (check the
mailing list).


regards,
Jim Kortge



|---------+------------------------------------------->
|         |           Adam Sherman                    |
|         |           <[hidden email]>            |
|         |           Sent by:                        |
|         |           [hidden email]|
|         |           ceforge.net                     |
|         |                                           |
|         |                                           |
|         |           11/30/2005 02:39 PM             |
|         |                                           |
|---------+------------------------------------------->
  >---------------------------------------------------------------------------------------------------------------------|
  |                                                                                                                     |
  |       To:       [hidden email]                                                               |
  |       cc:                                                                                                           |
  |       Subject:  [Beanshell-users] String.format()                                                                   |
  >---------------------------------------------------------------------------------------------------------------------|




String.format() under Java 1.5 seems to use a rather peculier syntax
with a variable number of arguments. Is it possible to call this
method from a bsh script?

Thanks,

A.

--
Adam Sherman
Technologist


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log
files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
<a href="http://ads.osdn.com/?ad_idv37&alloc_id865&op=click">http://ads.osdn.com/?ad_idv37&alloc_id865&op=click
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users





-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
<a href="http://ads.osdn.com/?ad_idv37&alloc_id865&op=click">http://ads.osdn.com/?ad_idv37&alloc_id865&op=click
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|

Re: String.format()

Adam Sherman
Thanks to both of you for the concise response. Am I permitted to
complain about Java's new run on syntactic sugar?

If I wanted to use Python, I'd use Python! :-|

Thanks,

A.


On 11/30/05, [hidden email] <[hidden email]> wrote:

> (Okay, Daniel beat me to it...)
>
>
> Under the covers, format(String format, Object... args) is really
> format(String format, Object[] args).
>
> bsh % print(String.format("local time is %tT", new Object[]
> {Calendar.getInstance()}));
> local time is 15:21:49
>
> I think there are plans to add varargs to the BeanShell syntax (check the
> mailing list).
>
>
> regards,
> Jim Kortge
>
>
>
> |---------+------------------------------------------->
> |         |           Adam Sherman                    |
> |         |           <[hidden email]>            |
> |         |           Sent by:                        |
> |         |           [hidden email]|
> |         |           ceforge.net                     |
> |         |                                           |
> |         |                                           |
> |         |           11/30/2005 02:39 PM             |
> |         |                                           |
> |---------+------------------------------------------->
>   >---------------------------------------------------------------------------------------------------------------------|
>   |                                                                                                                     |
>   |       To:       [hidden email]                                                               |
>   |       cc:                                                                                                           |
>   |       Subject:  [Beanshell-users] String.format()                                                                   |
>   >---------------------------------------------------------------------------------------------------------------------|
>
>
>
>
> String.format() under Java 1.5 seems to use a rather peculier syntax
> with a variable number of arguments. Is it possible to call this
> method from a bsh script?
>
> Thanks,
>
> A.
>
> --
> Adam Sherman
> Technologist
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep through log
> files
> for problems?  Stop!  Download the new AJAX search engine that makes
> searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
> <a href="http://ads.osdn.com/?ad_idv37&alloc_id865&op=click">http://ads.osdn.com/?ad_idv37&alloc_id865&op=click
> _______________________________________________
> Beanshell-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/beanshell-users
>
>
>
>


--
Adam Sherman
Technologist


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
<a href="http://ads.osdn.com/?ad_idv37&alloc_id865&op=click">http://ads.osdn.com/?ad_idv37&alloc_id865&op=click
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users