Software Archive
Read-only legacy content
17061 Discussions

string equality with .EQ. and CASE

Robinson__Donald
Beginner
209 Views
Create a pair of 5-char strings, str1 and str2. Assign the first with str1='' and leave str2 alone. Then assign "mw2" to them both, character-by-character. Positions 4:5 of str1 will contain space characters (ichar=32); str2 will contain nulls (ichar=0). When placed in a test for equality by .EQ. or CASE SELECT, str1 will match a string "mw2" in the test; str2 won't. str1 will return LEN_TRIM=3; str2 will return LEN_TRIM=5. This behavior seems inconsistent. Shouldn't null (0) and space (32) behave the same way? Any comments would be welcome.
0 Kudos
2 Replies
Intel_C_Intel
Employee
209 Views
Two comments:
  • Initialize all variables before using. (don't just 'leave str2 alone')

  • There are cases where null (0) and space (32) don't behave the same way (mixed language programming for one)


  • hth,
    John
    0 Kudos
    Steven_L_Intel1
    Employee
    209 Views
    In Fortran, NUL is just another non-printing character and is not treated the same as a space.
    0 Kudos
    Reply