StrPosition
概述
StrPosition 函数用于查找子字符串在字符串中首次出现的位置。该函数返回子字符串在字符串中出现的起始位置索引,如果子字符串未找到,则返回0。
语法说明
参数说明
| 参数 | 必需 | 参数类型 | 说明 |
|---|---|---|---|
| 字符串 | 是 | 字段、表达式、常量 | 需要搜索的字符串 |
| 子字符串 | 是 | 字段、表达式、常量 | 需要查找的子字符串 |
示例:
查找子字符串在产品描述中的位置
假设在一个产品数据表中,产品描述存储在名为 ProductDescription 的字段中。我们希望找到子字符串 "iPhone" 在每个产品描述中的位置,可以使用如下表达式:
示例公式
数据示例
| ProductID | ProductDescription |
|---|---|
| P001 | "Latest Apple iPhone 13" |
| P002 | "Samsung Galaxy S21 Ultra" |
| P003 | "Apple iPad Pro with M1" |
| P004 | "Google Pixel 5 Smartphone" |
| P005 | "Apple iPhone SE" |
计算结果
通过上述 StrPosition 函数表达式,结果将会是:
| ProductID | ProductDescription | Position |
|---|---|---|
| P001 | "Latest Apple iPhone 13" | 14 |
| P002 | "Samsung Galaxy S21 Ultra" | 0 |
| P003 | "Apple iPad Pro with M1" | 0 |
| P004 | "Google Pixel 5 Smartphone" | 0 |
| P005 | "Apple iPhone SE" | 7 |