Re: How to compare two strings?



Rich Townsend wrote in message ...
>jane.sync@xxxxxxxxx wrote:
>> I think I got it. Does the following code look like something a Fortran
>> programmer would use to test two strings?
>>
>> function evaluateinput(str1) result(string)
>> implicit none
>> character(12) str1
>> character(12) string
>> if (LLT(str1,'test')) then
>> string = 'less than'
>> else if (LGT(str1,'test')) then
>> string = 'greater than'
>> else
>> string = 'equal'
>> end if
>> return
>> end

>I think you've found a work-around, not a fix. The problem is the declaration of
>str1. If you pass a string of length shoother than 12, (say, 5), then the
>characters of str1 from position 6 onwards will contain garbage. It is this
>garbage that prevents str1 from being equal to 'test'; but the collating
>operators (LLT and LGT)

These are functions, not operators.

> will still work.

>The fix? Replace
>
>character(12) str1
>
>by
>
>character(*) strl

str1




.



Relevant Pages

  • Re: Changing filenames from Greeklish => Greek (subprocess complain)
    ... Your file names are turned to garbage. ... Fix ... and then use file names as strings. ... uploading filenames as greek-iso bytes. ...
    (comp.lang.python)
  • Re: Intersect of 2 strings
    ... if (IsPartialMatch(str2, str1, j, i, n)) // found best intersect ... We really don't know whether the OP intends to only qualify purely overlapping strings, or he's truly looking for the character-by-character intersection of two strings. ... Even if we assume he really means to only match contiguous characters, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Bash help: Indexing into multiple tab delimited strings in a single loop...
    ... > I have written a bash script that reads 4 tab delimited strings from files. ... > in a single loop, something like this in C derivative: ... > for element in str1 ...
    (comp.os.linux.misc)
  • Re: Streitfrage
    ... Parameter sollten als eigene Verwendungen von Strings gezählt werden, und eine Zuweisung an Str1 oder Str2 sollte dann die lokale Variable s nicht ändern. ...
    (de.comp.lang.delphi.misc)
  • Re: Substring check within VBA
    ... (remove nothere from the email address if mailing direct) ... > If Str1 and Str2 are strings, is there a function or simple coding within ... > to return TRUE if Str1 is a substring of Str2, ...
    (microsoft.public.excel.programming)