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:
Return Value:
|
Example 1:
DIM Position% Position% = INSTR("12345abc67890", "abc") PRINT Position%
Result:
6
Example 2:
DIM Position% Position% = INSTR("12345abc67890", "AbC", 5, 1) PRINT Position%
Result:
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:
Return Value:
|
Example:
DIM Position% Position% = INSTRREV("12345abc67890", "abc") PRINT Position%
Result:
Position% will equal 6
The example below demonstrates INSTRREV.
DIMint1%DIMstr1$, 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:
Return Value:
|
CONTAINEDIN function
Syntax: RetVal% = CONTAINEDIN(Match$, MainArray [,Comparison%]) Parameters:
Return Value:
|
Example:
SETCN[]ASCHARPTR"&",",",":","+","-","*","/","^",";","=","<",">","THEN",""ENDSETDIMc1, c2DIMiDIMxDIMyDIMStk$[128]DIMNdxDIMA$ A$="if x = 1 then y = y + 1 : if y > 10 THEN y = 0"CALLTinyParse(A$," ")c1=0c2=0FORi=0TONdx x=CONTAINEDIN(Stk$[i], CN,1)IFx <>-1THEN"Token "; i;" in A$ "; Stk$[i];" "; y=CONTAINEDIN(Stk$[i], CN)IFy <>-1THEN" exact match"c2++ELSE" match with case difference"ENDIFc1++ENDIFNEXT"A total of"; c1;" tokens, regardless of case, in CN[] where found in A$,"; c2;" were exact matches"getchar()c1=0c2=0FORi=0TONdx x=CONTAINEDIN(Stk$[i], CN,3)IFx <>-1THEN"the"; i;"th token in A$ "; Stk$[i];" "; y=CONTAINEDIN(Stk$[i], CN,2)IFy <>-1THEN" 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]ENDIFc1++ENDIFNEXTgetchar()SUBTinyParse(A$, Delim$)DIMRAWTB$DIMRAWSepDIMSTATIC ii Ndx=0TB$=""Sep=INCHR(A$, Delim$)IFSep >0THENIFSep >1THENTB$=LEFT$(A$, Sep-1)Stk$[ii]=TB$ ii++ENDIFA$=MID$(A$, Sep+1)TinyParse(A$, Delim$)ELSEStk$[ii]=A$ Stk$[ii+1]=""Ndx=ii ii=0ENDIFENDSUB
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:
Return Value:
|