contents   index   previous   next



StrIndex

 

f90VB Modules

 

f90VBDefs, f90VBBStrings

Summary

 

Function StrIndex returns the starting position of the first occurrence of a sub string within a string.

Syntax

 

integer(LONG_KIND) function StrIndex (Str, StrSub

{
character(len=*),intent(in):: Str |
integer(OLECHAR_KIND),dimension(:),intent(in):: Str |
type(OLESTRING),intent(in):: Str |
integer(BSTRHNDL_KIND),intent(in):: Str
}
{
character(len=*),intent(in):: StrSub |
integer(OLECHAR_KIND),dimension(:),intent(in):: StrSub |
type(OLESTRING),intent(in):: StrSub |
integer(BSTRHNDL_KIND),intent(in):: StrSub
}
 

Arguments

 

Str [Input]

String searched for the sub string specified in StrSub. It can be any of the f90VB string types (Fortran Strings, Fixed OLE Strings, Fortran OLE Strings or BStrings).

 

StrSub [Input]

String searched for in Str. It can be any of the f90VB string types (Fortran Strings, Fixed OLE Strings, Fortran OLE Strings or BStrings).

Comments

 

Function StrIndex returns the starting position of the first instance of StrSub inside Str. If StrSub is not found inside Str, or if Str is shorter than SubStr, function StrIndex returns zero. If StrSub is an empty or null string, StrIndex returns 1. If Str and SubStr are empty or null, StrIndex also returns 1.

When Str and SubStr are of different types, StrIndex converts StrSub to the same type of Str for the search operation. During this process, StrIndex will use the default system code page and conversion flags. If you want to perform a search using a user-specified code page and flags, you should first convert SubStr to the same type of Str using subroutine StrCopy, then call StrIndex.

Examples

 

program StrIndexExamples

 

!Demonstrates the use of StrIndex

!Copyright 1999-2000, Canaima Software

!All rights reserved

 

!load f90VB modules

use f90VBDefs

use f90VBBStrings

implicit none

 

 

!Declare an OLE string

integer(OLECHAR_KIND)::FxOLEStr(20)

!Declare Fortran OLE Strings

type(OLESTRING)::OLEStr,OLEStrSub

!Declare BStrings

integer(BSTRHNDL_KIND)::BStr,BStrSub

 

character(len=100)::FStr

 

 

!Initialize strings

call StrCopy('the brown fox',BStr)

call StrCopy(BStr,OLEStr)

call StrCopy(BStr,FxOLEStr)

 

!Print searched string

call StrCopy(FxOLEStr,FStr)

print *,'Searched string is:',trim(Fstr)

 

!print position of search string 'fox'

print *,'First instance of "fox" starts at:',StrIndex(BStr,'fox')

print *,'First instance of "fox" starts at:',StrIndex(OLEStr,'fox')

print *,'First instance of "fox" starts at:',StrIndex(FxOLEStr,'fox')

 

!Create a search OLE string

call StrCopy('brown',OLEStrSub)

!Print position of search OLE string

print *,'First instance of "brown" starts at:',StrIndex(BStr,OLEStrSub)

print *,'First instance of "brown" starts at:',StrIndex(OLEStr,OLEStrSub)

print *,'First instance of "brown" starts at:',StrIndex(FxOLEStr,OLEStrSub)

 

!Show results for a null (empty) search string

 

!Create a null Fortran OLE String

call StrCopy('',FxOLEStr)

print *,'First instance of "" starts at:',StrIndex(BStr,FxOLEStr)

print *,'First instance of "" starts at:',StrIndex(OLEStr,FxOLEStr)

print *,'First instance of "" starts at:',StrIndex(FStr,FxOLEStr)

 

!free memory used by dynamic strings

call StrFree(OLEStr)

call StrFree(BStr)

call StrFree(OLEStrSub)

call StrFree(BStrSub)

 

stop

end

Related Topics

 

For information about See
Extracting a sub string from a f90VB string StrSub
Creating a new BString StrCopy, BStrAlloc
Creating a new Fortran OLE String StrCopy, OLEStrAlloc

 


StrLCase / StrUCase