Re: [eclipse-users] sprintf?

From: Kish Shen <kisshen_at_cisco.com>
Date: Mon, 27 Aug 2007 07:04:14 +0100
Hi Malcolm,

Malcolm Ryan wrote:
> Is there an equivalent to 'sprintf' in eclipse? That is, a version of  
> printf/3 which writes its output to a string variable rather than to  
> a stream?
>
> Malcolm
>
>   
You can do what you want by using a stream device that is a string 
(string stream) or a memory
buffer (queue stream) -- these are (pseudo-)I/O devices that you can 
specify when you open
the stream. Here is an example with  string streams:

[eclipse 8]: open(string(""), write, S),
                printf(S, "Hello there %d", [1]),
        get_stream_info(S, name, String), close(S).


S = 7
String = "Hello there 1"

The `trick' here is the `name' of the stream is irs content - hence the 
use of get_stream_info/3.

Cheers,

Kish
> --
> Many clever men like you have trusted to civilisation.
> Many clever Babylonians, many clever Egyptians,
> Many clever men at the end of Rome.
>                                - G.K.Chesterton, The Napoleon of  
> Notting Hill
>
>
>
>
> _______________________________________________
> ECLiPSe-Users mailing list
> ECLiPSe-Users_at_crosscoreop.com
> http://www.crosscoreop.com/mailman/options/eclipse-users
>   
Received on Mon Aug 27 2007 - 07:04:48 CEST

This archive was generated by hypermail 2.2.0 : Thu Feb 02 2012 - 02:31:58 CET