StrLen
f90VB Modules
f90VBDefs, f90VBBStrings
Summary
Function StrLen returns the length in number of characters of the input string's buffer.
Syntax
| integer(LONG_KIND) function StrLen | (Str) |
| { | |
| character(len=*),intent(in):: | Str | |
| integer(OLECHAR_KIND),dimension(:),intent(in):: | Str | |
| type(OLESTRING),intent(in):: | Str | |
| integer(BSTRHNDL_KIND),intent(in):: | Str |
| } | |
Arguments
Str [Input]
String whose length will be determined. It can be any of the f90VB string types (Fortran Strings, Fixed OLE Strings, Fortran OLE Strings or BStrings).
Comments
Function StrLen is f90VB's analog to Fortran's intrinsic function len().
Argument Str
When Str is a Fortran String, StrLen result is equivalent to that of len().
When Str is a Fixed OLE String, function StrLen returns size(Str)-1, or 0 if the Str vector has not been allocated.
When Str is a Fortran OLE String, function StrLen returns the maximum number of characters that the string can hold under the current allocation. This may be the same or higher than the number of characters currently stored in the string. If the Fortran OLE String has not been allocated before calling StrLen, the function returns zero.
When Str is a BString, function StrLen usually returns the number of characters currently stored in the string, as this is generally the same as the size of the BString buffer. However, if the BString was allocated using BStrAlloc, StrCopy, or BStrReAlloc with a StrLen argument, function StrLen returns the value passed in the StrLen argument. If Str is a null handle, or a handle to an empty BString, function StrLen returns zero.
Note on Multibyte strings: f90VB uses Fortran Strings to store ANSI and Multibyte strings. However, in a Multibyte string, a single character may use up to two bytes of storage, which is the equivalent to two ANSI characters. When the argument passed to StrLen is a Multibyte string, the function will correctly return the number of Multibyte string characters.
Examples
| program StrLenExamples |
!Demonstrates the use and the differences
!between StrLen, StrLenTrim, StrByteLen and StrByteLenTrim
!copyright 1999, Canaima Software
!All rights reserved
!load f90VB modules
use f90VBDefs
use f90VBBStrings
implicit none
!declare a Fortran String
character(len=20)::FStr
!declare a fixed OLE String
integer(OLECHAR_KIND)::FxOLEStr(20)
!declare a Fortran OLE String
type(OLESTRING)::OLEStrA, OLEStrB
!declare a BString
integer(BSTRHNDL_KIND)::BStr
!utility variables
character(len=100)::TmpFStr
!initialize strings
call StrCopy('The brown fox', FxOLEStr)
call StrCopy(FxOLEStr,BStr,StrLen=30)
call StrCopy(BStr,OLEStrA,StrLen=25)
call StrCopy(BStr,OLEStrB)
call StrCopy(FxOLEStr, FStr)
!print string lengths
print *,'String:', trim(FStr)
print *,'FStr:'
print *,'StrLen(FStr):',StrLen(FStr)
print *,'StrLenTrim(FStr):',StrLenTrim(FStr)
print *,'StrByteLen(FStr):',StrByteLen(FStr)
print *,'StrByteLenTrim(FStr):',StrByteLenTrim(FStr)
print *,''
print *,'FxOLEStr:'
print *,'StrLen(FxOLEStr):',StrLen(FxOLEStr)
print *,'StrLenTrim(FxOLEStr):',StrLenTrim(FxOLEStr)
print *,'StrByteLen(FxOLEStr):',StrByteLen(FxOLEStr)
print *,'StrByteLenTrim(FxOLEStr):',StrByteLenTrim(FxOLEStr)
print *,''
print *,'OLEStrA:'
print *,'StrLen(OLEStrA):',StrLen(OLEStrA)
print *,'StrLenTrim(OLEStrA):',StrLenTrim(OLEStrA)
print *,'StrByteLen(OLEStrA):',StrByteLen(OLEStrA)
print *,'StrByteLenTrim(OLEStrA):',StrByteLenTrim(OLEStrA)
print *,''
print *,'OLEStrB:'
print *,'StrLen(OLEStrB):',StrLen(OLEStrB)
print *,'StrLenTrim(OLEStrB):',StrLenTrim(OLEStrB)
print *,'StrByteLen(OLEStrB):',StrByteLen(OLEStrB)
print *,'StrByteLenTrim(OLEStrB):',StrByteLenTrim(OLEStrB)
print *,''
print *,'BStr:'
print *,'StrLen(BStr):',StrLen(BStr)
print *,'StrLenTrim(BStr):',StrLenTrim(BStr)
print *,'StrByteLen(BStr):',StrByteLen(BStr)
print *,'StrByteLenTrim(BStr):',StrByteLenTrim(BStr)
!free memory used by dynamic strings
call StrFree(OLEStrA)
call StrFree(OLEStrB)
call StrFree(BStr)
stop
end
Related Topics
| For information about | See | |
| Getting the length in bytes of a string | StrByteLen | |
| Getting the trimmed length of a string | StrLenTrim | |
| Getting the trimmed length in bytes of a string | StrByteLenTrim | |