diff --git a/src/framework/MOM_string_functions.F90 b/src/framework/MOM_string_functions.F90 index e5e5df681b..64c14ad213 100644 --- a/src/framework/MOM_string_functions.F90 +++ b/src/framework/MOM_string_functions.F90 @@ -255,7 +255,7 @@ end function extractWord endif endif enddo - if (b<=ns) extract_word = trim(string(b:ns)) + if (b<=ns .and. nw==n-1) extract_word = trim(string(b:ns)) end function extract_word !> Returns string with all spaces removed. @@ -298,6 +298,8 @@ logical function string_functions_unit_tests() call localTest(extractWord("One Two,Three",3),"Three") call localTest(extractWord("One Two, Three",3),"Three") call localTest(extractWord(" One Two,Three",1),"One") + call localTest(extract_word("One,Two,Three",",",3),"Three") + call localTest(extract_word("One,Two,Three",",",4),"") write(*,*) '==========================================================' contains subroutine localTest(str1,str2)