Chop leading chars string from str.
Note that trailing spaces are not ignored in either string.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | str |
original string |
||
| character(len=*), | intent(in) | :: | chars |
characters to strip |
new string
pure function lchop(str, chars) result(newstr) character(len=*),intent(in) :: str !! original string character(len=*),intent(in) :: chars !! characters to strip character(len=:),allocatable :: newstr !! new string ! this logic here is to account for trailing spaces, which we preserve if (len(chars)>len(str)) then newstr = str ! not possible to chop else if (str==chars) then if (len(str)>len(chars)) then newstr = str(len(chars)+1:) ! only trailing spaces remain else newstr = '' ! string is now empty end if else if (index(str,chars) == 1) then newstr = str(len(chars)+1:) ! chop leading chars, keep rest of string else newstr = str ! original string, noting to chop end if end if end if end function lchop