Created
October 4, 2012 12:26
-
-
Save ponderomotion/3833266 to your computer and use it in GitHub Desktop.
Split a string into 2 either side a delimiter in FORTRAN
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
! 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 |
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
What will happen if delimiter spears at position 1?
for example "hello;world" with semicolon as delimiter works, but how about
";hello"