Skip to content

Instantly share code, notes, and snippets.

@ponderomotion
Created October 4, 2012 12:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ponderomotion/3833266 to your computer and use it in GitHub Desktop.
Save ponderomotion/3833266 to your computer and use it in GitHub Desktop.
Split a string into 2 either side a delimiter in FORTRAN
! split a string into 2 either side of a delimiter token
SUBROUTINE split_string(instring, string1, string2, delim)
CHARACTER(30) :: instring,delim
CHARACTER(30),INTENT(OUT):: string1,string2
INTEGER :: index
instring = TRIM(instring)
index = SCAN(instring,delim)
string1 = instring(1:index-1)
string2 = instring(index+1:)
END SUBROUTINE split_string
@kookma
Copy link

kookma commented Feb 10, 2018

What will happen if delimiter spears at position 1?
for example "hello;world" with semicolon as delimiter works, but how about
";hello"

@MaximeLee
Copy link

What will happen if delimiter spears at position 1?
for example "hello;world" with semicolon as delimiter works, but how about
";hello"

In my opinion, there is no use to do that in the first place since it beats the role of a delimiter which is to separate data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment