Sv Find

From GECK
Jump to: navigation, search


A function added by the New Vegas Script Extender.

Description

Returns the position of the first occurrence of a string in a string variable.

The first argument is a string, which may have optional formatting information thereafter. This is what you want to find.

The second argument (ignoring the optional formatting) is a string variable within which to search for the first string.

There are three optional int arguments at the very end: a start position and end position, which allow searching of a substring of the string_var, and finally, a boolean flag to enable case sensitivity.

Syntax

[help]
(int) Sv_Find toFind:string 20xOptional:formatting within:string_var startPos:int numChars:int caseSensitiveFlag:int 

Example

Sv_Find "this", MyStringVar

Additional Context

string_var my_message

let my_message := "The owls are not what they seem"

Sv_Find "e", my_message ; will return 2, the first 'e'

Sv_Find "the", my_message ; will return 0, note case insensitivy- it found 'The'

Sv_Find "owls", my_message ; will return 4

Sv_Find "something that isn't in the string", my_message ; will return -1

Warning, remember it returns the position, not true or false. Hence:

string_var my_instructions

let my_instructions := "Do Something"

if eval (Sv_Find "Do Something", my_instructions)
    ; Is False, because it returns zero as the found position
endif

if (Sv_Find "Not in string", my_instructions)
    ; Is True, because it returns -1 for 'not found', and that reduces to true
endif

; * If you just want to know if something was found, use this:

if eval (Sv_Find "Do Something", my_instructions) > -1
    ; Do something is somewhere in the variable
endif


See Also