StrCompare
f90VB Modules
f90VBDefs, f90VBBStrings
Summary
Function StrCompare allows lexical comparisons of two strings of the same type. It will return a Fortran Logical (.TRUE. or .FALSE.) as its result.
Syntax
| logical function StrCompare | (StrA, RelationalOp, StrB, CaseSensitive) |
| { | |
| character(len=*),intent(in):: | StrA |
| character(len=*),intent(in):: | StrB |
| } | | |
| { | |
| integer(OLECHAR_KIND),dimension(:),intent(in):: | StrA |
| integer(OLECHAR_KIND),dimension(:),intent(in):: | StrB |
| } | | |
| type(OLESTRING),intent(in):: | StrA |
| type(OLESTRING),intent(in):: | StrB |
| } | | |
| { | |
| integer(BSTRHNDL_KIND),intent(in):: | StrA |
| integer(BSTRHNDL_KIND),intent(in):: | StrB |
| } | |
| character(len=*),intent(in):: | RelationalOp |
| logical,intent(in):: | CaseSensitive |
Arguments
StrA [Input]
String to be used on the left side of the relational operator. It can be any of the f90VB string types (Fortran Strings, Fixed OLE Strings, Fortran OLE Strings or BStrings).
StrB [Input]
String to be used on the right side of the relational operator. It can be any of the f90VB string types (Fortran Strings, Fixed OLE Strings, Fortran OLE Strings or BStrings), but it must be of the same type as StrA.
RelationalOp [Input]
Fortran string indicating the relational operation to verify. See comments for a description of allowed operators.
CaseSensitive [Input]
A logical argument indicating whether the comparison between both strings should be case-sensitive.
Comments
StrA and StrB must be of the same type. If argument CaseSensitive is set to .TRUE., the performed comparison is case sensitive. StrCompare returns .TRUE. if the relation indicated in RelationalOp is satisfied; the result is .FALSE. if the relation specified by RelationalOp is not satisfied.
The following table shows the relational operators recognized by StrCompare.
| RelationalOp | Relationship | StrCompare result | |
| '.LT.' or 'LT' or '<' | Less than | .TRUE. if StrA is less than StrB | |
| '.LE.' or 'LE' or '<=' | Less than or Equal to | .TRUE. if StrA is less than or equal to StrB | |
| '.GT.' or 'GT' or '>' | Greater than | .TRUE. if StrA is greater than StrB | |
| '.GE.' or 'GE' or '>=' | Greater than or Equal to | .TRUE. if StrA is greater than or equal to StrB | |
| '.EQ.' or 'EQ' or '==' | Equal to | .TRUE. if StrA is equal to StrB | |
| '.NE.' or 'NE' or '/=' | Not Equal to | .TRUE. if StrA is not equal to StrB | |
Examples
| program StrCompareExamples |
!Demonstrates the use of StrCompare
!Copyright 1999-2000, Canaima Software
!All rights reserved
!load f90VB modules
use f90VBDefs
use f90VBBStrings
implicit none
!declare an array of BStrings
integer(BSTRHNDL_KIND),dimension(4)::BSVect
!declare a vector of relational operators
character(len=4)::CompOp(4)
!utility variables
integer::i,j,k
character(len=25)::FStrL, FStrR
!Fill out BString vector
call StrCopy('ABC',BSVect(1))
call StrCopy('abc',BSVect(2))
call StrCopy('AaBC',BSVect(3))
call StrCopy('CD',BSVect(4))
!print strings for reference
print *,'Compared Strings:'
print *,''
do i=1,4
call StrCopy(BSVect(i),FStrL)
print *,'String #',i,':'
print *,' Length:', StrLenTrim(BSVect(i))
print *,' Content: ',trim(FStrL)
enddo
!fill out vector of relational operators
CompOp(1)='.eq.'
CompOp(2)='.le.'
CompOp(3)='.ge.'
CompOp(4)='.ne.'
!Perform a batch of comparisons and print results
print *,''
print *,'Case Insensitive Comparisons:'
do i=1,4
do j=1,4
call StrCopy(BSVect(i),FStrL)
call StrCopy(BSVect(j),FStrR)
print *,(trim(FStrL),CompOp(k),trim(FStrR),':', &
StrCompare(BSVect(i),CompOp(k),BSVect(j)), ' ', &
k=1,4)
enddo
enddo
print *,''
print *,'Case Sensitive Comparisons:'
do i=1,4
do j=1,4
call StrCopy(BSVect(i),FStrL)
call StrCopy(BSVect(j),FStrR)
print *,(trim(FStrL),CompOp(k),trim(FStrR),':', &
StrCompare(BSVect(i),CompOp(k),BSVect(j),.true.), ' ', &
k=1,4)
enddo
enddo
stop
end