---
title: "How to Convert Integers to String in Fortran?"  
description: "How to Convert Integers to String in Fortran?"  
author: "Anonymous User"  
published: 2014-11-19  
updated: 2014-11-19  
canonical: https://www.mindstick.com/forum/12641/how-to-convert-integers-to-string-in-fortran  
category: "asp.net"  
tags: ["c#"]  
reading_time: 1 minute  

---

# How to Convert Integers to String in Fortran?

I have a [program](https://www.mindstick.com/blog/12337/scaling-up-your-mentorship-program) in [Fortran](https://answers.mindstick.com/qa/36849/does-learning-fortran-have-a-future-bright-enough-to-double-my-efforts-to-master-it) that saves the [results](https://yourviews.mindstick.com/story/4497/usage-of-baking-soda-magical-results) to a [file](https://www.mindstick.com/articles/59/encrypting-and-decrypting-files-using-c-sharp). At the moment I open the file using

OPEN (1, FILE = 'Output.TXT')

However, I [now](https://yourviews.mindstick.com/view/81402/it-s-liberals-vs-progressives-in-us-politics-now) want to run a loop, and save the results of each iteration to the [files](https://www.mindstick.com/articles/23302/the-importance-and-advantage-of-keeping-your-important-files-on-the-cloud) 'Output1.TXT', 'Output2.TXT', 'Output3.txt', ...

Is there an easy way in Fortran to constuct filenames from the loop [counter](https://www.mindstick.com/interview/33859/how-to-create-pixel-counter-in-javascipt) i?

## Replies

### Reply by Mark M

you can write to a unit, but you can also write to a string

**program foo**

```
    character(len=1024) :: filename    write (filename, "(A5,I2)") "hello", 10    print *, trim(filename)
```

**end program**

Please note (this is the second trick I was talking about) that you can also build a format string programmatically.

**program foo**

```
    character(len=1024) :: filename    character(len=1024) :: format_string    integer :: i    do i=1, 10        if (i < 10) then            format_string = "(A5,I1)"        else            format_string = "(A5,I2)"        endif        write (filename,format_string) "hello", i        print *, trim(filename)    enddoend program
```


---

Original Source: https://www.mindstick.com/forum/12641/how-to-convert-integers-to-string-in-fortran

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
