INSTR function
Purpose: INSTR searches through a string to locate a substring. If the substring is found, the function returns an integer indicating the position of the beginning of the substring. The search begins by default from the beginning of the string to be searched or, optionally, from a specified start postion.
Syntax: Position% = INSTR(MainStr$, Match$ [,Start%] [,CaseSensitivity%]) Parameters:
|
Example 1 :
Position% = INSTR("12345abc67890", "abc")
Result:
Position% will equal 6
Example 2 :
DIM Position% Position% = INSTR("12345abc67890", "AbC", 5, 1) PRINT Position%
Result:
Position% will equal 6
BCX Console Sample Programs using INSTR function.
S14.bas S39.bas S84.bas S87.bas
INSTRREV function
Purpose: INSTRREV searches backwards through a string to locate a substring. If the substring is found, the function returns an integer indicating the position of the beginning of the substring. The search begins by default from the end of the string to be searched or, optionally, from a specified start position.
Syntax: Position% = INSTRREV(MainStr$, Match$ [,Start%] [,CaseSensitivity%]) Parameters:
|
Example:
Position% = INSTRREV("12345abc67890", "abc")
Result:
Position% will equal 6
The example below demonstrates INSTRREV.
DIM
int1%DIM
str1$, str2$""
"Example 1 demonstrates two parameter INSTRREV"
"looks for last backslash "
str1$=
"I:\like\this\one\better\bob.exe"
=
MID$
(
str1$,1
,INSTRREV
(
str1$,"\"
)
)
""
"Example 2 demonstrates three parameter INSTRREV"
str1$=
"12345678XXX23456XXX0"
""
"Start looking backwards from position 12 for XXX"
"in string 12345678XXX23456XXX0"
int1%=
INSTRREV
(
str1$,"XXX"
,12
)
" result should be 9"
""
"Start looking backwards from position 20 for XXX"
"in string 12345678XXX23456XXX0"
int1%=
INSTRREV
(
str1$,"XXX"
,20
)
" result should be 17"
""
' XXX changed to XYY.
str1$=
"12345678XYY23456XXX0"
""
"Start looking backwards from position 12 for XXX"
"in string 12345678XYY23456XXX0"
int1%=
INSTRREV
(
str1$,"XXX"
,12
)
" result should be 0"
INCHR function
Purpose: INCHR returns the position where the single character Matchar$ is located in MainStr$. INCHR is approximately four times faster than INSTR.
Syntax: Position% = INCHR(MainStr$,Matchar$) Parameters:
|
CONTAINEDIN function
Syntax: RetVal% = CONTAINEDIN(Match$, MainArray [,Comparison%]) Parameters:
|
Example:
SET
CN[
]
AS
CHAR
PTR
"&"
,","
,":"
,"+"
,"-"
,"*"
,"/"
,"^"
,";"
,"="
,"<"
,">"
,"THEN"
,""
END
SET
DIM
c1, c2DIM
iDIM
xDIM
yDIM
Stk$[
128
]
DIM
NdxDIM
A$ A$=
"if x = 1 then y = y + 1 : if y > 10 THEN y = 0"
CALL
TinyParse(
A$," "
)
c1=
0
c2=
0
FOR
i=
0
TO
Ndx x=
CONTAINEDIN
(
Stk$[
i]
, CN,1
)
IF
x <>-
1
THEN
"Token "
; i;" in A$ "
; Stk$[
i]
;" "
; y=
CONTAINEDIN
(
Stk$[
i]
, CN)
IF
y <>-
1
THEN
" exact match"
c2+
+
ELSE
" match with case difference"
END
IF
c1+
+
END
IF
NEXT
"A total of"
; c1;" tokens, regardless of case, in CN[] where found in A$,"
; c2;" were exact matches"
getchar(
)
c1=
0
c2=
0
FOR
i=
0
TO
Ndx x=
CONTAINEDIN
(
Stk$[
i]
, CN,3
)
IF
x <>-
1
THEN
"the"
; i;"th token in A$ "
; Stk$[
i]
;" "
; y=
CONTAINEDIN
(
Stk$[
i]
, CN,2
)
IF
y <>-
1
THEN
" exact match of the"
; y;"th token in CN[] "
; CN$[
y]
c2+
+
ELSE
" match with case difference of the"
; x;"th token in CN[] "
; CN$[
x]
END
IF
c1+
+
END
IF
NEXT
getchar(
)
SUB
TinyParse(
A$, Delim$)
DIM
RAW
TB$DIM
RAW
SepDIM
STATIC ii Ndx=
0
TB$=
""
Sep=
INCHR
(
A$, Delim$)
IF
Sep >0
THEN
IF
Sep >1
THEN
TB$=
LEFT$
(
A$, Sep-
1
)
Stk$[
ii]
=
TB$ ii+
+
END
IF
A$=
MID$
(
A$, Sep+
1
)
TinyParse(
A$, Delim$)
ELSE
Stk$[
ii]
=
A$ Stk$[
ii+
1
]
=
""
Ndx=
ii ii=
0
END
IF
END
SUB
FINDINTYPE function
Purpose: FINDINTYPE is modeled after the CONTAINEDIN function. The main differences between CONTAINEDIN and FINDINTYPE are:
Syntax: RetVal% = FINDINTYPE(Match$, _ Type.element, _ RangeFrom%, _ RangeTo% _ [, Comparison%] _ [, Index%]) Parameters:
|