# MapSubstring - 脚本函数

MapSubstring 脚本函数用于将任何表达式的一部分映射至先前加载的映射表。映射区分大小写且不重复，子字符串会从左至右映射。

语法：

MapSubstring('map\_name', expression)

返回数据类型： 字符串

参数：

MapSubstring 参数

| 参数 | 说明 |
| --- | --- |
| map\_name | 先前在 mapping load 或 mapping select 语句中读取的映射表的名称。名称必须必须用直的单引号括起来。<br><br>警告注释如果您在宏扩展变量中使用此函数并引用不存在的映射表，函数调用将失败且不会创建字段。 |
| expression | 结果被子字符串映射的表达式。 |

示例：

在此例中，我们加载产品型号的列表。每一种产品型号都拥有一组使用复合代码描述的属性。使用带有 MapSubstring 的映射表，我们可以展开属性代码的描述。

```
map2: mapping LOAD *  Inline [ AttCode, Attribute R, Red Y, Yellow B, Blue C, Cotton P, Polyester S, Small M, Medium L, Large ] ;  Productmodels: LOAD *, MapSubString('map2', AttCode) as Description Inline [ Model, AttCode Twixie, R C S Boomer, B P L Raven, Y P M Seedling, R C L SeedlingPlus, R C L with hood Younger, B C with patch MultiStripe, R Y B C S/M/L  ] ; // We don't need the AttCode anymore Drop Field 'AttCode';
```

最终生成的表格如下所示：

Example 1

| Model | Description |
| --- | --- |
| Twixie | Red Cotton Small |
| Boomer | Blue Polyester Large |
| Raven | Yellow Polyester Medium |
| Seedling | Red Cotton Large |
| SeedlingPlus | Red Cotton Large with hood |
| Younger | Blue Cotton with patch |
| MultiStripe | Red Yellow Blue Cotton Small/Medium/Large |

## 了解详情

* [](https://help.qlik.com/zh-CN/qlikview/May2024/Subsystems/Client/Content/QV_QlikView/Scripting/ScriptPrefixes/Mapping.htm)[Mapping](https://help.qlik.com/zh-CN/qlikview/May2024/Subsystems/Client/Content/QV_QlikView/Scripting/ScriptPrefixes/Mapping.htm)
* [在脚本中使用引号](https://help.qlik.com/zh-CN/qlikview/May2024/Subsystems/Client/Content/QV_QlikView/Scripting/use-quotes-in-script.htm)