Tutorial

Getting Started with Macros

Macro Editor

User Interface

Menus and Toolbar

Editing Macro Statements

Expression Editor

Macro Debugging

How To

Using variables

Finding and modifying objects

Creating new page content

Asking for user input

Storing persistent data

Using binary data

Sorting objects

Macro menus

Bulleted and numbered lists

Sample Macros

Concepts

Expressions

Objects

Properties

Variables

Data Types

Arrays

Functions

Literals

Operators

Comments

Last updated on: March 19, 2023
Also available as a single HTML file

Onetastic Macro Documentation > Functions > String Functions > String_FindFirst

String_FindFirst

Finds the first occurence of a search string in an input string. Returns true if the string was found and the offset it was found at, false otherwise.

Syntax

Bool String_FindFirst(
	String string, 
	String search, 
	Numeric offset, 
	Bool ignoreCase, 
	out Numeric foundAt)

Parameters

String string
String to search in.
String search
The substring to search for.
Numeric offset
Offset of the input string to start search from. If non-negative, search will start this number of characters counted from the beginning of the string. If negative, the search will start this number of characters counted from the end of the string.
Bool ignoreCase
Ignores the case of the strings if set to true.
out Numeric foundAt
If the search string is found, the offset of the first occurence is stored in this variable.

Examples

// 1 2 3 4 // 01234567890123456789012345678901234567890 $string = "a4 b6 c5 4a b6 d5 f6 d7 e4 b6 c2 56 d4 5a" // ^ ^ ^ // Instances of b6 are marked with ^ // Find first instance String_FindFirst($string, "b6", 0, false, $foundAt) // Returns true, $foundAt is 3 // Find first instance after index 9 String_FindFirst($string, "b6", 9, false, $foundAt) // Returns true, $foundAt is 12 // Find first instance within the last 20 characters String_FindFirst($string, "b6", -20, false, $foundAt) // Returns true, $foundAt is 27 // Not found String_FindFirst($string, "f9", 0, false, $foundAt) // Returns false, $foundAt is not modified // Case Sensitive String_FindFirst("The quick brown fox jumps over the lazy dog", "the", 0, false, $foundAt) // Returns true, $foundAt is 31 // Case Insensitive String_FindFirst("The quick brown fox jumps over the lazy dog", "the", 0, true, $foundAt) // Returns true, $foundAt is 0

Reference

Statements

For

ForEach

If

Else If

Else

Switch

Case

Default

While

Expression

Comment

Break

Continue

Return

Hierarchy Objects

NotebookRoot

Notebook

SectionGroup

Section

Page

Page Objects

Title

Outline

Table

Column

Row

Cell

Paragraph

Text

Image

EmbeddedFile

Tag

Other Objects

DialogBox

MacroMenu

Window

Functions

Array Functions

Color Functions

Data Store Functions

Date/Time Functions

Dialog Box Functions

Macro Execution Functions

Macro Menu Functions

Object Functions

String Functions

Window Functions