Class IndexOf
- Namespace
- YndigoBlue.Velocity.Functions
- Assembly
- YndigoBlue.Velocity.dll
Represents the CHARINDEX/INSTR function that finds the position of a substring within a string.
public class IndexOf : Function, ICheckItem, IDefaultItem, IFilterItem, IElement
- Inheritance
-
IndexOf
- Implements
Remarks
The CHARINDEX (SQL Server) or INSTR (Oracle) function returns the starting position of a substring within a string. Returns 0 if the substring is not found. Position indexing is typically 1-based. This function is useful for parsing, validation, and conditional logic based on string content.
Examples
Find the position of the "@" symbol in each email address:
var schema = manager.LoadSchema("crm");
var contacts = schema["contacts"];
var query = new Query()
.Select([ contacts["id"], new Expression("at_position", new IndexOf(contacts["email"], "@")) ])
.From(contacts);
var results = manager.Retrieve(query);
Constructors
- IndexOf(IElement, IElement)
Initializes a new instance of IndexOf with generic elements.
- IndexOf(Column, string)
Initializes a new instance of IndexOf with a literal substring.
- IndexOf(Column, Column)
Initializes a new instance of IndexOf with a column-based substring.
- IndexOf(Expression, string)
Initializes a new instance of IndexOf for a string expression.