@@ -328,3 +328,63 @@ program demo_find
328
328
329
329
end program demo_find
330
330
```
331
+
332
+ <!-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -->
333
+ ### ` format_string `
334
+
335
+ #### Description
336
+
337
+ Format or transfer a integer/real/complex/logical variable as a character sequence.
338
+
339
+
340
+ #### Syntax
341
+
342
+ ` format_string = [[stdlib_strings(module):format_string(interface)]] (value, [, format]) `
343
+
344
+ #### Status
345
+
346
+ Experimental
347
+
348
+ #### Class
349
+
350
+ Pure function
351
+
352
+ #### Argument
353
+
354
+ - ` value ` : Integer/real/complex/logical scalar.
355
+ This argument is intent(in).
356
+ - ` format ` : Character scalar like ` '(F6.2)' ` .
357
+ This argument is intent(in) and optional.
358
+
359
+ #### Result value
360
+
361
+ The result is a allocatable length Character scalar.
362
+
363
+ #### Example
364
+
365
+ ``` fortran
366
+ program demo_strings_format_string
367
+ use, non_intrinsic :: stdlib_strings, only: format_string
368
+ implicit none
369
+ print *, 'format_string(complex) : '
370
+ print *, format_string((1, 1)) ! (1.00000000,1.00000000)
371
+ print *, format_string((1, 1), '(F6.2)') ! (1.00,1.00)
372
+ print *, format_string((1, 1), '(F6.2)'), format_string((2, 2), '(F7.3)') ! (1.00,1.00)(2.000,2.000)
373
+ print *, 'format_string(integer) : '
374
+ print *, format_string(100) ! 100
375
+ print *, format_string(100, '(I6)') ! 100
376
+ print *, format_string(100, '(I6)'), format_string(1000, '(I7)') ! 1001000
377
+ print *, 'format_string(real) : '
378
+ print *, format_string(100.) ! 100.000000
379
+ print *, format_string(100., '(F6.2)') ! 100.00
380
+ print *, format_string(100., '(F6.2)'), &
381
+ format_string(1000., '(F7.3)'), format_string(1000, '(F7.3)') ! 100.00********
382
+ !! Wrong demonstration
383
+ print *, 'format_string(logical) : '
384
+ print *, format_string(.true.) ! T
385
+ print *, format_string(.true., '(L2)') ! T
386
+ print *, format_string(.false., '(L2)'), format_string(.true., '(L5)'), &
387
+ format_string(.false., '(I5)') ! FT*
388
+ !! Wrong demonstration
389
+ end program demo_strings_format_string
390
+ ```
0 commit comments