FindStr

FindStr( value, find, [start] )
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

Argument Type Definition and Requirements

value

The string to search in.

find

The string to search for.

start

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 value of 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.

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

Console.WriteLine(result);
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]
System.out.println(
    client.query(
        Arr(
            FindStr("fire and fireman", "fire"),
            FindStr("fire and fireman", "fire", 4)
        )
    ).get());
[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', err))
[ 0, 9 ]
result = client.query(
  [
    q.find_str("fire and fireman", "fire"),
    q.find_str("fire and fireman", "fire", 4),
  ]
)
print(result)
[0, 9]
println(Await.result(
    client.query(
        Arr(
            FindStr("fire and fireman", "fire"),
            FindStr("fire and fireman", "fire", 4)
        )
    ),
    5.seconds
))
[0, 9]

Was this article helpful?

We're sorry to hear that.
Tell us how we can improve!
Visit Fauna's Discourse forums or email docs@fauna.com

Thank you for your feedback!