×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

How to write an integer value into a string with leading zeros?

How to write an integer value into a string with leading zeros?

How to write an integer value into a string with leading zeros?

(OP)
Help....

I am constructing a entity name in and I need to construct the name from strings and integers.  This I know how to do, but I don't know how to get the leading zeros. For example:

integer*4     val1
character*3   chr1
character*3   chr2
character*10  ans

val1 = 1
chr1 = 'LST'

write(chr2,*) val1

ans = val1 // chr2   !gives me  LST  1
                            !what I want is:
                            ! LST001

Any help would, as always, be greatly appreciated.



RE: How to write an integer value into a string with leading zeros?

mjs84,

WRITE (ans, '(a, i3.3)') chr1, val1

RE: How to write an integer value into a string with leading zeros?

(OP)
toog

Thanks a ton!!!!!

mjs84

RE: How to write an integer value into a string with leading zeros?

Readers who wish to learn more how this works, please refer to internal files section of your favorite Fortran textbook.  Thank you mjs84 and toog for addressing a valuable topic.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources