string - Fortran中如何检查两个字符串是否相等?

标签 string fortran strcmp

我想检查两个字符串是否相等并做一些工作。

character(len = 50) :: x, y ,z  
x="amin"    
y="amin"
if(llt(x, y)) then
  z=x
end if

我写了这个,但它只是检查字符串中的第一个字符。 我该如何处理?

最佳答案

在 Fortran 中,两个字符串可以通过关系运算进行比较,即 < , > , == , /= , etc. .
所以在你的情况下:

if ( x == y ) then
  z = x 
end if 

llt()函数做了完全不同的事情:

The llt() function tests whether a string is lexically less than another string based on the ordering of the ASCII collating sequence.

关于string - Fortran中如何检查两个字符串是否相等?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59739472/

相关文章:

java - Java中按制表符分割

java - 来自介绍性程序员的 classcastException : conversion from object to String

gcc - gfortran编译器错误: result of exponentiation exceeds the range of INTEGER(4)

c - 在 if() 语句中使用 strcmp() 作为条件如何工作?

c - 在使用套接字进行进程间通信期间,strcmp 的行为似乎很奇怪

linux - bash 脚本删除文件中的字符串

r - 反斜杠转义数字 '\1' 到 '\7' 在 R 字符串中意味着什么,为什么它们比较错误?

fortran - 通过子程序将一组变量值传递给没有公共(public) block 的函数有哪些方法?

arrays - Fortran:哪种方法可以更快地更改数组的等级? ( reshape 与指针)

c++ - strcmp() 的问题没有正确比较字符串