Str: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: Str
| Old | New | Line | |
|---|---|---|---|
| 1 | + | The [[Procedure|procedure]] [`str`](https://www.freepascal.org/docs-html/rtl/system/str.html) converts an ordinal or [[Real|real]] type value to a string representation thereof. It is a [[UCSD Pascal]] extension that was picked up and generalized by [[Borland Pascal]]. The [[FPC|FreePascal compiler]] supports it, too, as described here. | |
| 2 | + | ||
| 3 | + | ## invocation | |
| 4 | + | ||
| 5 | + | The formal signature of `str` cannot be written in [[Pascal]], hence a description follows: | |
| 6 | + | ||
| 7 | + | `Str` requires two parameters. The first parameter has to be an ordinal or real type expression. The second parameter specifies the destination. It has to be a [[Variable parameter|variable]] of the type [[String|string]] (or an `array[dimension] of char`). | |
| 8 | + | ||
| 9 | + | The first parameter may optionally be followed by a [[Colon|colon]] and an [[Integer|integer]] expression. This will determine the minimum width of the generated string representation. However, bear in mind if the destination variable is a *fixed*-length string, no *more* characters than its maximum capacity can be stored. In this case any surplus characters will be clipped. | |
| 10 | + | ||
| 11 | + | If the first parameter is a `real` expression, the parameter may be followed by another colon and integer after the first colon and integer specifying the minimum width. This number, however, will determine the number of decimal places after the radix mark. | |
| 12 | + | ||
| 13 | + | ## formatting | |
| 14 | + | ||
| 15 | + | Specifying a second formatting for the `real` number representation will disable the usual scientific notation. | |
| 16 | + | ||
| 17 | + | Enumerated type values will be left-justified, numeric values will be right-justified. | |
| 18 | + | ||
| 19 | + | `Str` cannot produce decimal numbers containing a [[Comma|comma]] as a [[DecimalSeparator|radix mark]]. | |
| 20 | + | ||
| 21 | + | `Str` only produces numbers to the base of ten. [[FPC|FPC’s]] standard [[RTL|run-time library]] provides the functions [`binStr`](https://www.freepascal.org/docs-html/rtl/system/binstr.html), [`octStr`](https://www.freepascal.org/docs-html/rtl/system/octstr.html), and [`hexStr`](https://www.freepascal.org/docs-html/rtl/system/hexstr.html), which produce string representations of integers according to base of two, eight and sixteen respectively. `Real` values cannot be easily represented in other bases. | |
| 22 | + | ||
| 23 | + | ## see also | |
| 24 | + | ||
| 25 | + | - the standardized [[WriteStr|writeStr procedure]] which does very same operation, but accepts an “infinite” number of arguments | |
| 26 | + | - [[Val|val]] which performs the reverse operation | |
| 27 | + | - [String operations](https://BorlandPascal.FanDom.com/wiki/String_operations) in *BorlandPascal Fandom Wiki* | |
| 28 | + | ||
| 29 | + | --- | |
| 30 | + | *From the Free Pascal wiki, page "Str", as it stood on 2023-03-05 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
