Repository navigation
Instr
Home › String Functions › InStr
Returns the position of the first match, or 0 if there is none.
Declare Function InStr ( ByRef str As Const String, [ Any ] ByRef substring As Const String ) As Integer
Declare Function InStr ( ByRef str As Const WString, [ Any ] ByRef substring As Const WString ) As Integer
Declare Function InStr ( ByVal start As Integer, ByRef str As Const String, [ Any ] ByRef substring As Const String ) As Integer
Declare Function InStr ( ByVal start As Integer, ByRef str As Const WString, [ Any ] ByRef substring As Const WString ) As Integerstrsubstringstartstr
Locates the position of the first occurrence of a substring or character within a string. In the first form of InStr (without start parameter), the search begins at the first character.
Zero (0) is returned if: either substring is not found, either str or substring are empty strings, or start < 1.
If the Any keyword is specified, InStr returns the first occurrence of any character in substring.
The position of the first occurrence of substring in str.
first = InStr( [ start, ] str, [ Any ] substring )
- The wide-character string version of
InStris not supported for DOS target.
- QB returns
startifsearchis a zero length string. - QB does not support Unicode.
' It will return 4
Print InStr("abcdefg", "de")
' It will return 0
Print InStr("abcdefg", "h")
' It will search for any of the characters "f", "b", "c", and return 2 as "b" is encountered first
Print InStr("abcdefg", Any "fbc")Dim test As String
Dim idx As Integer
test = "abababab"
idx = InStr(test, "b")
Do While idx > 0 'if not found loop will be skipped
Print """b"" at " & idx
idx = InStr(idx + 1, Test, "b")
Loop'A Unicode example:
dim text as wstring*20
text = "Привет, мир!"
print instr(text,"ет") ' displays 5
Category: String Functions
Kind: function
Reproduced from the FreeBASIC Wiki Manual under the GNU Free Documentation License 1.3 — with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. Copyright © the FreeBASIC project and wiki contributors. See License.
tiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Lambdas
- Block Strings
- Partial Types
- String Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- PsControls
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing