*NIX Tricks

[f77] Concatenate a string with another string or an integer in fortran 77

Posted in fortran, programming by kousik on March 23, 2011

Let’s assume that we have defined two strings as

str1 = 'abc'

str2 = 'pqr'

and an  integer

integ = 25

(Make sure str1 and str2, and integ are defined as character strings, and integer, respectively)

1. Concatenate str1 and str2 into str3 (make sure you define str3 first as a character string)

str3 = str1//str2

2. Concatenate str1 and integ into str3 (again make sure str3 is defined as a character string)

step a: convert integer to a string first (make sure str4 is defined as a character string and not initialized, i.e. it’s so far an empty string)

write(str4,'(I5)') integ

step b: concatenate str1 and str4 into str3

str3 = str1//str4

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.