| 1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" |
| 2 |
"http://www.w3.org/TR/html4/strict.dtd"> |
| 3 |
<html> |
| 4 |
<head> |
| 5 |
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> |
| 6 |
<title>sprintf</title> |
| 7 |
<meta http-equiv="Content-Style-Type" content="text/css"> |
| 8 |
<link rel="stylesheet" href="../../style.css" type="text/css"> |
| 9 |
</head> |
| 10 |
|
| 11 |
<body> |
| 12 |
|
| 13 |
|
| 14 |
<h1>sprintf</h1> |
| 15 |
|
| 16 |
<p> |
| 17 |
Returns formatted output. <em>(version 4.52 or later)</em> |
| 18 |
</p> |
| 19 |
|
| 20 |
<pre class="macro-syntax"> |
| 21 |
sprintf FORMAT [ARGUMENT ...] |
| 22 |
</pre> |
| 23 |
|
| 24 |
<h2>Remarks</h2> |
| 25 |
|
| 26 |
<p> |
| 27 |
FORMAT controls the output as in C language printf with ARGUMENTs converted to proper type first. |
| 28 |
The output string is stored in the string variable <inputstr>. |
| 29 |
</p> |
| 30 |
|
| 31 |
<table> |
| 32 |
<caption>supported format style</caption> |
| 33 |
<tr> |
| 34 |
<th>type</th> |
| 35 |
<td>c, d, i, o, u, x, X, e, E, f, g, G, a, A and s</td> |
| 36 |
</tr> |
| 37 |
<tr> |
| 38 |
<th>flags(option)</th> |
| 39 |
<td>-, +, 0, # and blank(' ')</td> |
| 40 |
</tr> |
| 41 |
<tr> |
| 42 |
<th>width(option)</th> |
| 43 |
<td>decimal integer or *</td> |
| 44 |
</tr> |
| 45 |
<tr> |
| 46 |
<th>precision(option)</th> |
| 47 |
<td>nonnegative decimal integer or *(option), preceded by a period(.)</td> |
| 48 |
</tr> |
| 49 |
</table> |
| 50 |
|
| 51 |
<p> |
| 52 |
Please specify the floating point number with the string variable and string because the |
| 53 |
TTL can not support the floating point number. |
| 54 |
</p> |
| 55 |
|
| 56 |
<p> |
| 57 |
As a result of this command, the system variable "result" is set to one of the following values. |
| 58 |
</p> |
| 59 |
|
| 60 |
<table> |
| 61 |
<tr> |
| 62 |
<th>Value</th> |
| 63 |
<th>Status</th> |
| 64 |
</tr> |
| 65 |
<tr> |
| 66 |
<td>0</td> |
| 67 |
<td>Formatted successfully</td> |
| 68 |
</tr> |
| 69 |
<tr> |
| 70 |
<td>1</td> |
| 71 |
<td>No format string</td> |
| 72 |
</tr> |
| 73 |
<tr> |
| 74 |
<td>2</td> |
| 75 |
<td>Invalid format</td> |
| 76 |
</tr> |
| 77 |
<tr> |
| 78 |
<td>3</td> |
| 79 |
<td>Invalid argument</td> |
| 80 |
</tr> |
| 81 |
</table> |
| 82 |
|
| 83 |
<h2>Example</h2> |
| 84 |
|
| 85 |
<pre class="macro-example"> |
| 86 |
sprintf 'Tera Term 4.%d' 51 |
| 87 |
messagebox inputstr 'sprintf test(1)' |
| 88 |
|
| 89 |
sprintf 'Windows %d (+%s)' 2000 'SP4' |
| 90 |
messagebox inputstr 'sprintf test(2)' |
| 91 |
|
| 92 |
sprintf '%s=%d %s=0x%x' 'dec' 10 'hex' 33 |
| 93 |
messagebox inputstr 'sprintf test macro(3)' |
| 94 |
|
| 95 |
sprintf 'pi=%f' "3.14159" |
| 96 |
messagebox inputstr 'sprintf test macro(4)' |
| 97 |
|
| 98 |
sprintf 'pi=%.4e' "3.14159" |
| 99 |
messagebox inputstr 'sprintf test macro(5)' |
| 100 |
|
| 101 |
sprintf 'pi=%.4g' "3.14159" |
| 102 |
messagebox inputstr 'sprintf test macro(6)' |
| 103 |
</pre> |
| 104 |
|
| 105 |
<h2>See also</h2> |
| 106 |
<ul> |
| 107 |
<li><a href="sprintf2.html">sprintf2</a></li> |
| 108 |
</ul> |
| 109 |
|
| 110 |
</body> |
| 111 |
</html> |