比较 Fortran 中的两个字符串

Huz*_*uzo 8 string fortran string-comparison fortran77

什么是比较两个字符串说,正确的方法abc,并bcd根据字母顺序?是否有内置命令可以这样做?或者会>.lt.做没有任何问题的工作?

fra*_*lus 6

The intrinsic relational operators .lt. and < (along with the "equal" and "greater than" friends) indeed may be used to compare character variables.

We see the definition (Fortran 2018, 10.1.5.5.1):

the character operand x1 is considered to be less than x2 if the character value of x1 at this position precedes the value of x2 in the collating sequence

where the comparison is done with the first character part in the corresponding strings which differ.

The collating sequence tells you whether, for example, 'a' precedes 'b'. So, if 'abc' is compared with 'bcd' then the comparison is between 'a' and 'b'.

如果要比较的两个字符串的长度不同,则执行比较时,就好像较短的字符串在右侧填充空格(空格)以使其与较长的字符串长度相同。这意味着当比较'ab''abc'我们看'ab ''abc''ab'<'abc'当且仅当' '<'c'