FindStr

This reference topic applies to FQL v4. Go to this page for the latest FQL v10 reference topics.

FindStr( value, find, [start] )
FindStr( value, find, [start] )
FindStr( value, find, [start] )
find_str( value, find, [start] )
FindStr( value, find, [start] )

Description

The FindStr function returns the offset position of a string within another string, or -1 if the string is not found.

Parameters

Parameter Type Definition and Requirements

value

String

The String to search in.

find

String

The String to search for.

start

Integer

Optional - The position in the value string where the search starts. The default value, if omitted, is 0 characters. The first position in the string is 0. If the value is less than 0, then the start value is ignored.

Although we mention characters, technically, we are talking about code points. In Unicode, a code point is usually, but not always, a character. Code points can sometimes represent single characters, but can also represent formatting and other non-alphanumeric characters.

For example, the character é can be the single character "e" that includes an acute accent (U+00E9), or it could be displayed as a single character but be composed of an "e" (U+0065) and a "combining" acute accent (U+0301). Visually, you cannot distinguish between the two.

Returns

A Integer indicating the position where the find string starts. If the find string is not found in the value string, -1 is returned.

Examples

The following query executes an array of independent FindStr operations and returns the results in an array. The result array position matches the execution array position. The first operation takes a string to search ("fire and fireman"), locates the first occurrence of the search string "fire", and places the offset in the first position of the result array. The second operation uses the same search string ("fire and fireman") and attempts to locate the first occurrence of the word "fire" after the fourth character in the string. The result of 9 is placed into the second position of the result array.

try
{
    Value result = await client.Query(
        Arr(
            FindStr("fire and fireman", "fire"),
            FindStr("fire and fireman", "fire", 4)
        )
    );

    Console.WriteLine(result);
}
catch (Exception e)
{
    Console.WriteLine($"ERROR: {e.Message}");
}
Arr(LongV(0), LongV(9))
result, err := client.Query(
	f.Arr{
		f.FindStr("fire and fireman", "fire"),
		f.FindStr("fire and fireman", "fire", f.Start(4)),
	})

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
[0 9]
client.query(
  [
    q.FindStr('fire and fireman', 'fire'),
    q.FindStr('fire and fireman', 'fire', 4),
  ]
)
.then((ret) => console.log(ret))
.catch((err) => console.error(
  'Error: [%s] %s: %s',
  err.name,
  err.message,
  err.errors()[0].description,
))
[ 0, 9 ]
result = client.query(
  [
    q.find_str("fire and fireman", "fire"),
    q.find_str("fire and fireman", "fire", 4),
  ]
)
print(result)
[0, 9]
[
  FindStr('fire and fireman', 'fire'),
  FindStr('fire and fireman', 'fire', 4),
]
[ 0, 9 ]
Query metrics:
  •    bytesIn: 101

  •   bytesOut:  18

  • computeOps:   1

  •    readOps:   0

  •   writeOps:   0

  •  readBytes:   0

  • writeBytes:   0

  •  queryTime: 3ms

  •    retries:   0

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!