home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1999 August
/
Chip_1999-08_cd.bin
/
zkuste
/
VBasic
/
Data
/
Priklady
/
iinstr.bas
< prev
next >
Wrap
BASIC Source File
|
1997-04-10
|
3KB
|
85 lines
Attribute VB_Name = "modEnhancedInstr"
Option Explicit
Function iInStr%(ByVal startpos%, ByVal searchstring$, ByVal searchfor$, ByVal ignorechar$)
' Description
' Searches for one string inside another, ignoring all occurences inside a given
' pair of characters
'
' Parameters
' Name Type Contains
' -----------------------------------------------------------------------------
' searchstring String The string to search in
' searchfor String The string to search for
' startpos Integer The position to start searching
' ignorechar String The character that signales that occurences
' to be ignored
' Returns
' The position of the first occurence
'
' Uses
' <Module name>:<Procedure Name>
'
' Last modified by
' Jens Balchen : Date 1996-11-30 : Rev 1.0.0 : First working version
Dim iPos%
Dim ignore_%()
Dim ignorecount%
Dim found%
Dim i%
' Find all ignore characters in the parameter string
iPos = InStr(startpos%, searchstring, ignorechar$)
ignorecount% = 0
Do While iPos <> 0
' Add to array
ignorecount% = ignorecount% + 1
ReDim Preserve ignore_(ignorecount%)
ignore_(ignorecount%) = iPos
iPos = InStr(iPos + 1, searchstring, ignorechar$)
' Check if the next character is also an ignore character, in
' which case we don't add. This applies only if the index is an even number
If ignorecount% Mod 2 <> 0 Then
If Mid$(searchstring, iPos + 1, 1) = ignorechar$ Then
' Ignore
ignorecount% = ignorecount% - 1
End If
End If
Loop
' Search for the search string, ignoring all occurences inside two ignore
' characters
iPos% = InStr(startpos%, searchstring$, searchfor$)
Do While iPos% <> 0
found% = True
For i% = 1 To ignorecount% - 1
If ignore_%(i%) < iPos% And iPos% < ignore_%(i% + 1) Then
' Check i%
If (i% Mod 2 <> 0) Then
' This isn't OK.
found% = False
Exit For
Else
' This is OK
' Return this position
iInStr% = iPos%
Exit Function
End If
End If
Next i%
If Not found% Then
iPos% = InStr(iPos% + 1, searchstring$, searchfor$)
Else
iInStr% = iPos%
Exit Function
End If
Loop
' If we made it here, no more were found
iInStr% = 0
End Function