注释
社区兴趣团体现已从 Yammer 迁移到Microsoft Viva Engage。 若要加入 Viva Engage 社区并参与最新讨论,请填写 “请求访问财务和运营 Viva Engage 社区 ”表单,然后选择要加入的社区。
本文介绍字符串运行时函数。
火柴
在另一个字符串中搜索字符串或表达式。
int match(str pattern, str text)
参数
| 参数 | Description |
|---|---|
| 模式 | 要搜索的字符串或表达式。 |
| 文本消息 | 要搜索的字符串。 |
返回值
如果模式位于字符串中,则为 1;否则为 0(零)。
注解
搜索不区分大小写。 以下特殊字符可用于为模式参数创建 模式 。
\:反斜杠(\)对特殊字符的特殊处理进行 null 处理或转义,以便像普通字母一样匹配特殊字符。 一对反斜杠被转换为一个非特定反斜杠。 示例:
- match(“ab$cd”,“ab$cd”); 返回 0。
- match(“ab\$cd”,“ab$cd”); 返回 0。 反斜杠不会转义。
- match(“ab\\$cd”,“ab$cd”); 返回 1。 反斜杠和美元符号被逃脱。
< 或 ^:表达式开头的左尖括号(<)或绕行符(^)用于匹配行的开头。 示例:
- match(“<abc”,“abcdef”); 返回 1。
- match(“abc”,“<defabc”); 返回 0。
- match(“^abc”,“abcdef”); 返回 1。
- match(“^abc”,“defabc”); 返回 0。
> 或 $:表达式末尾的右尖括号(>)或美元符号($)用于匹配行尾。 示例:
- match(“abc”,“abcdef>”); 返回 0。
- match(“abc>”,“defabc”); 返回 1。
? 或。:问号(?)或句点(.)匹配同一位置中的任何一个字符。 示例:
- match(“abc.def”,“abc#def”); 返回 1。
- match(“colou?r”,“colouXr”): 返回 1。
:x: 冒号 (:) 指定要匹配的字符组,如紧随其后的字符指示。
:a:将匹配项设置为字母。 示例:
- match(“ab:acd”,“ab#cd”); 返回 0。
- match(“ab:acd”,“abxyzcd”): 返回 0。
- match(“ab:acd”,“abxcd”): 返回 1。
:d:将匹配项设置为数字字符。 示例:
- match(“ab:dcd”,“ab3cd”): 返回 1。
- match(“ab:dcd”,“ab123cd”): 返回 0。
- match(“ab:dcd”,“abcd”); 返回 0。
:n: 将匹配项设置为字母数字字符。 示例:
- match(“ab:ncd”,“ab%cd”; 返回 0。
- match(“ab:ncd”,“ab9cd”): 返回 1。
- match(“ab:ncd”,“abXcd”); 返回 1。
:SPACE: SPACE 是空格字符 (“ ) 将匹配项设置为空白、制表和控件字符,如 Enter(新行)。 示例:
- match(“ab: cd”,“ab cd”); 返回 1。
- match(“ab: cd”,“ab\ncd”); 返回 1。
- match(“ab: cd”,“ab\tcd”); 返回 1。
- match(“ab: cd”,“ab cd”); 返回 0。 仅匹配第一个空间。
*:后跟星号(“*”)的表达式需要匹配上述表达式的零、一个或多个匹配项。 示例:
- match(“abc*d”,“abd”); 返回 1。
- match(“abc*d”,“abcd”): 返回 1。
- match(“abc*d”,“abcccd”): 返回 1。
- match(“abc*d”,“abxd”); 返回 0。
+:后跟加号(+)的表达式需要匹配上述表达式的一个或多个匹配项。 示例:
- match(“abc+d”,“abd”): 返回 0。
- match(“abc+d”,“abcd”): 返回 1
- match(“abc+d”,“abcccd”): 返回 1。
- match(“abc+d”,“abxd”): 返回 0。
-:后跟减号(-)的表达式需要匹配上述表达式的零个或一个匹配项。 换句话说,上述表达式是可选的。 示例:
- match(“colou-r”,“color”): 返回 1。
- match(“colou-r”,“颜色”): 返回 1。
[]:将单个字符与括在括号中的任何字符匹配。 字符范围可以由用减号分隔的两个字符指定(-)。 例如, [a-z] 匹配 a 和 z 之间的所有字母, [0-9] 匹配数字, [0-9a-f] 匹配十六进制数字。 示例:
- match(“[abc]”,“apple”); 返回 1,因为它与“apple”中的 a 匹配。
- match(“[abc]”,“kiwi”); 返回 0,因为“kiwi”不包含 a、b 或 c。
- match(“gr[ae]y”,“灰色”); 返回 1。 此表达式还匹配“灰色”。
- match(“gr[ae]y”,“graey”): 返回 0,因为匹配“gr”和“y”之间的一个字符。
[^]:如果括在方括号中的文本中的第一个字符是一个绕行符(^),则表达式将匹配括号中括起来的字符以外的所有字符。 示例:
- match(“[^bc]at”,“bat”; 返回 0。
- match(“[^bc]at”,“hat”; 返回 1。
- match(“[^abc]”,“bat”); 返回 1。 除 a、b 或 c 之外的任何内容都匹配。 因此,匹配 t。
strAlpha
仅复制字符串中的字母数字字符。
str strAlpha(str _text)
参数
| 参数 | Description |
|---|---|
| _发短信 | 要从中复制的字符串。 |
返回值
包含指定字符串中的所有字母数字字符的新字符串。
注解
例如, strAlpha(“2+2=5 是否正确?”) 返回字符串 225isthiscorrect。
Example
static void strAlphaExample(Args _arg)
{
str s;
;
s = strAlpha("?a*bc123.");
print s;
pause;
}
strCmp
比较两个文本字符串。
int strCmp(str text1, str text2)
参数
| 参数 | Description |
|---|---|
| text1 | 第一个字符串。 |
| text2 | 第二个字符串。 |
返回值
如果两 个字符串相同,则为 1 ;如果第一个字符串先排序,则为 -1;如果第二个字符串早于排序,则 为 -1 。
注解
此方法执行的比较区分大小写。
print strCmp("abc", "abc"); //Returns the value 0.
print strCmp("abc", "ABC"); //Returns the value 1.
print strCmp("aaa", "bbb"); //Returns the value -1.
print strCmp("ccc", "bbb"); //Returns the value 1.
strColSeq
将所有大写字符转换为小写字符,并将具有重音的所有字符转换为相应的不区分小写字符。
str strColSeq(str text)
参数
| 参数 | Description |
|---|---|
| 文本消息 | 要从中复制和转换字符的字符串。 |
返回值
转换后的文本字符串。
注解
strColSeq 函数存在以实现向后兼容性目的。 此函数仅支持以下西欧字符的映射:
- AàáââäÄÀÂÂÄÄBCçÇDEèéêèÉÊÊFGHIííîïÍÎÍÎJKLMNñOóóôõöÖÓÔÖÖPQRSTUúúûüÚÚÛÜVWXYíÍZäøÅÅ
- aaaaaaaaabcccdeeeeeeeeefgh iii iiijklmnnnooooooooooopqrstuuuvwxyyyz~ڂÇ~ڂÇ
对于符合 Unicode 的功能,请通过 DLL 和 DLLFunc 类使用 Win32 LCMapString 应用程序编程接口(API)。
Example
以下示例打印 abcdeabcde。
static void strColSeqExample(Args _arg)
{
;
print strColSeq("");
pause;
}
strDel
创建从中删除指定子字符串的字符串的副本。
str strDel(str _text, int _position, int _number)
参数
| 参数 | Description |
|---|---|
| _发短信 | 要从中复制的字符串。 |
| _位置 | 在复制作期间开始忽略字符的位置。 |
| _数 | 要忽略的字符数。 _number参数前面的减号指示_number-1 个字符之前,应将字符与_position的字符一起删除_position。 |
返回值
从字符串复制的剩余字符。
注解
strDel 函数是对子字符串函数的补充。
strDel("ABCDEFGH",2,3); //Returns the string "AEFGH".
strDel("ABCDEFGH",4,3); //Returns the string "ABCGH".
strFind
在字符串中搜索其中一个指定字符的第一个匹配项。
int strFind(str _text, str _characters, int _position, int _number)
参数
| 参数 | Description |
|---|---|
| _发短信 | 要搜索的字符串。 |
| _字符 | 要搜索的字符。 |
| _位置 | 搜索开始的字符串中的位置。 |
| _数 | 一个带符号数字,指示搜索的方向和字符串中要搜索的位置数。 |
返回值
指定字符之一的第一个匹配项的位置的值;如果未找到任何字符,则为 0。
注解
若要从字符串的开头到末尾进行搜索,请使用 1 作为 _position 参数的值。 如果 _number 参数的值为负值,则系统会从指定位置向后搜索字符数。 搜索不区分大小写。 下面是一个示例。
strFind("ABCDEFGHIJ","KHD",1,10); //Returns the value 4 (the position where "D" was found).
strFind("ABCDEFGHIJ","KHD",10,-10); //Returns the value 8 (the position where "H" was found).
strFind 函数是对 strNFind 函数的补充。
strFmt
设置指定字符串的格式,并将 n 个匹配项替换为第 n 个参数。
str strFmt(str _string, ...)
参数
| 参数 | Description |
|---|---|
| _字符串 | 要设置格式的字符串。 |
返回值
带格式的字符串。
注解
如果未为参数提供参数,则参数在字符串中返回为“%n”。 实际类型的值的字符串转换限制为两个小数位数。 值是舍入的,而不是截断的。 Microsoft .NET Framework 中的 System.String::Format 方法可用于获取更多功能,如示例中所示。
Example
static void strFmtExampleJob(Args _arg)
{
System.Double sysDouble;
real r = 8.3456789;
int i = 42;
utcDateTime utc = str2DateTime("2008-01-16 13:44:55" ,321); // 321 == YMD.
str s;
;
s = strFmt("real = %1, int = %2, utcDateTime = %3, [%4]", r, i, utc);
info("X1: " + s);
//
sysDouble = r;
s = System.String::Format("{0:##.####}", sysDouble);
info("N1: " + s);
//
s = System.String::Format("{0,6:C}", sysDouble); // $
info("N2: " + s);
/********** Actual Infolog output
Message (02:16:05 pm)
X1: real = 8.35, int = 42, utcDateTime = 1/16/2008 01:44:55 pm, [%4]
N1: 8.3457
N2: $8.35
**********/
}
strIns
通过将一个字符串插入另一个字符串来生成字符串。
str strIns(str _text1, str _text2, int _position)
参数
| 参数 | Description |
|---|---|
| _text1 | 要插入另一个字符串的字符串。 |
| _text2 | 要插入到其他字符串中的字符串。 |
| _位置 | 输出字符串中应出现 _text2 参数的第一个字符的位置。 |
返回值
组合的文本字符串。
注解
strIns 函数是对 strDel 函数的补充。 如果 _position 参数的值大于原始字符串的长度,则要插入的字符串将追加到原始字符串的末尾。
strIns("ABFGH","CDE",3); //Returns the string "ABCDEFGH".
strIns("ABCD","EFGH",10); //Returns the string "ABCDEFGH".
strKeep
仅使用第一个输入字符串中应保留的第一个输入字符串中的字符来生成字符串。
str strKeep(str _text1, str _text2)
参数
| 参数 | Description |
|---|---|
| _text1 | 包含可用于生成输出字符串的字符的字符串。 |
| _text2 | 指定要保留的输出字符串的字符的字符串。 |
返回值
保留的字符的字符串。
注解
strKeep("ABBCDDEFGHB","BCD"); //Returns the string "BBCDDB".
strKeep("abcZcba","bc") //Returns the string "bccb".
strKeep 函数是对 strRem 函数的补充。
strLen
计算指定字符串的长度。
int strLen(str text)
参数
| 参数 | Description |
|---|---|
| 文本消息 | 要计算其长度的字符串。 |
返回值
指定字符串的长度。
注解
strLen("ABC"); //Returns the value 3.
strLen("ABCDEFGHIJ"); //Returns the value 10.
strLine
从跨多行的字符串中检索单个行。
str strLine(str string, int count)
参数
| 参数 | Description |
|---|---|
| 字符串 | 一个可能跨越多行的字符串。 |
| 计数 | 要返回的行的偏移量。 |
返回值
由字符串参数指定的 字符串 的复制行。
注解
字符串的第一行偏移量为 0。 可以通过在字符串中嵌入 \n 或 \r\n 字符,为一个字符串分配多行。 此外,可以在左引号前立即使用 at sign (@),并使用 Enter 键将字符串值的一部分分散在 X++ 代码编辑器中的多行上。
Example
str mytxt = "first-line\nsecond-line\nlast-line";
// Prints "second-line".
print strLine(mytxt,1);
// Prints "last-line".
print strLine(mytxt,2);
strLTrim
从文本字符串中删除前导空白。
str strLTrim(str text)
参数
| 参数 | Description |
|---|---|
| 文本消息 | 要从中删除前导空白的字符串。 |
返回值
已从中删除前导空白的文本的字符串等效项。
注解
strLTrim 函数是对 strRTrim 函数的补充。
Example
// Returns the text string "ABC-DEFG".
strLTrim(" ABC-DEFG");
strLwr
将指定字符串中的所有字母转换为小写。
str strLwr(str _text)
参数
| 参数 | Description |
|---|---|
| _发短信 | 要转换为小写的字符串。 |
返回值
仅包含小写字母的指定字符串的副本。
注解
strLwr 函数是对 strUpr 函数的补充。 strLwr 函数在 Win32 API 中使用 LCMapString 函数。
Example
static void strLwrExample(Args _args)
{
// Returns the text string "abcdd55efghij".
print strLwr("Abcdd55EFGHIJ");
pause;
}
strNFind
在文本字符串的一部分中搜索未包含在指定字符列表中的字符的第一个匹配项。
int strNFind(str _text, str _characters, int _position, int _number)
参数
| 参数 | Description |
|---|---|
| _发短信 | 要搜索的文本字符串。 |
| _字符 | 要从搜索中排除的字符列表。 |
| _位置 | 字符串中开始搜索的位置。 |
| _数 | 一个有符号数字,指示搜索的方向和要搜索的位置数。 如果减号在_number之前,系统会按_position的反向顺序搜索_number字符。 |
返回值
_characters 参数未 指定的字符的第一个匹配项的位置,如果未找到,则为 0。
注解
搜索不区分大小写。 若要从字符串的开头到末尾进行搜索,请使用值 1 作为 _position 参数。 如果减号位于 _number 参数的值之前,则从 _position 参数指定的位置开始按反向顺序搜索字符。
strNFind("ABCDEFGHIJ","ABCDHIJ",1,10); //Returns the value 5 (the position of "E");
strNFind("CDEFGHIJ","CDEFGIJ",10,-10); //Returns the value 6 (the position of "H").
strNFind("abcdef","abCdef",3,2) //Returns the value 0.
strNFind("abcdef", "abcef",3,2) //Returns the value 4.
strNFind 函数是对 strFind 函数的补充。
strPoke
用另一个字符串覆盖字符串的一部分。
str strPoke(str _text1, str _text2, int _position)
参数
| 参数 | Description |
|---|---|
| _text1 | 原始字符串。 |
| _text2 | 要替换为原始字符串的一部分的字符串。 |
| _位置 | 开始替换字符的原始字符串的位置。 |
返回值
新字符串。
注解
新字符串可能比原始字符串长。 但是,如果 _position 参数的值大于字符串的长度,则返回原始字符串而不进行替换。
strPoke("12345678","AAA",3); //Returns the string "12AAA678".
strPoke("abcde","4567",4); //Returns the string "abc4567".
strPoke("abcde", "4567", "10"); //Returns the string "abcde".
strPrompt
追加具有指定句点字符数的字符串,后跟冒号和空格字符。
str strPrompt(str _string, _int len)
参数
| 参数 | Description |
|---|---|
| _字符串 | 原始字符串。 |
| _莱恩 | 字符串的所需最终长度。 |
返回值
类似于用户输入提示的字符串。
注解
在非典型情况下, 如果 _len 参数的值略高于原始字符串的长度,则为添加尾随空格提供最高优先级。 接下来,优先于冒号。 将优先顺序设置为句点。 _len参数的负值返回追加有尾随空格的输入字符串。
strPrompt("ab",-1); //Returns "ab ".
strPrompt("ab",3); //Returns "ab ".
strPrompt("ab",4); //Returns "ab: ".
strPrompt("ab",5); //Returns "ab.: ".
strPrompt("ab",6); //Returns "ab..: ".
Example
static void JobStrPromptDemo(Args _args)
{
// Printed string is "[abc..: ]"
print "[", strPrompt("abc", 7), "]";
pause;
}
strRem
从另一个字符串中删除一个字符串中指定的字符。
str strRem(str text1, str text2)
参数
| 参数 | Description |
|---|---|
| text1 | 要从中删除字符的字符串。 |
| text2 | 要从输出字符串中排除的字符。 |
返回值
原始字符串的剩余内容。
注解
此函数区分大小写。
strRem("abcd_abcd","Bc"); //Returns the string "abd_abd".
strRem("ABCDEFGABCDEFG","ACEG"); //Returns the string "BDFBDF".
此函数是 strKeep 函数的补充。
strRep
重复字符串字符。
str strRep(str _text, str _number)
参数
| 参数 | Description |
|---|---|
| _发短信 | 要重复的字符串。 |
| _数 | 重复字符串的次数。 |
返回值
一个新字符串,其中包含重复指定次数的原始字符串的内容。
Example
以下示例打印文本字符串 ABABABABAB。
static void strRepExample(Args _arg)
{
str strL;
;
strL = strRep("AB",6);
print strL;
pause;
}
strRTrim
从字符串末尾删除尾随空格字符。
str strRTrim(str _text)
参数
| 参数 | Description |
|---|---|
| _发短信 | 要从中删除尾随空格字符的字符串。 |
返回值
不包含尾随空格字符的指定字符串的副本。
注解
strRTrim("ABC-DEFG- "); //Returns the string "ABC-DEFG-".
strRTrim(" CD "); //Returns " CD".
strRTrim 函数是对 strLTrim 函数的补充。
strScan
在文本字符串中搜索另一个字符串的匹配项。
int strScan(str _text1, str _text2, int _position, int _number)
参数
| 参数 | Description |
|---|---|
| _text1 | 要在其中搜索的字符串。 |
| _text2 | 要查找的字符串。 |
| _位置 | 要在其中执行比较 的_text1 参数中的第一个位置。 |
| _数 | 要重试比较 的_text1 参数中的位置数。 如果减号位于 _number 参数前面,则系统按从指定位置的反向顺序搜索字符数。 |
返回值
在字符串中找到指定字符串的位置;否则为 0 (零)。
注解
比较不区分大小写。 小于 1的 _position 参数的值被视为 1。 扫描的方向由 _number 参数中指定的符号控制。 正号表示每个连续比较开始一个靠近字符串末尾的位置。 负号表示每个比较都启动一个靠近字符串开头的位置。
strScan("ABCDEFGHIJ","DEF",1,10); //Returns the value 4.
strScan ("ABCDEFGHIJ","CDE",10,-10); //Returns the value 3.
strUpr
将字符串中的所有字母转换为大写。
str strUpr(str _text)
参数
| 参数 | Description |
|---|---|
| _发短信 | 要转换为大写字母的字符串。 |
返回值
仅包含小写字母的指定字符串的副本。
注解
strUpr 函数是对 strLwr 函数的补充。 strUpr 函数在 Win32 API 中使用 LCMapString() 函数。
Example
以下示例打印 ABCDD55EFGHIJ。
static void strUprExample(Args _args)
{
print strUpr("Abcdd55EFGhiJ");
pause;
}
subStr
检索字符串的一部分。
str subStr(str _text, int _position, int _number)
参数
| 参数 | Description |
|---|---|
| _发短信 | 原始字符串。 |
| _位置 | 要检索的部件开始的原始字符串中的位置。 |
| _数 | 一个带符号整数,指示要从原始字符串中检索的位置的方向和数量。 如果减号在 _number之前,系统将从指定位置向后选择子字符串。 |
返回值
原始字符串的子字符串。
注解
如果减号位于 _number 参数的值之前,则从指定位置向后选择子字符串。
subStr("ABCDEFGHIJ",3,5); //Returns the string "CDEFG".
subStr("ABCDEFGHIJ",7,-4); //Returns the string "DEFG".
subStr("abcdef",2,99) //Returns the string "bcdef".
subStr("abcdef",2,3) //Returns the string "bcd".
subStr("abcdef",2,-3); //Returns the string "ab".
strContains
检查文本字符串是否包含另一个字符串。
boolean strContains(str _text, str _potentialContains)
参数
| 参数 | Description |
|---|---|
| _发短信 | 要在其中搜索的原始字符串。 |
| _potentialContains | 要查找的字符串。 |
返回值
如此 如果原始字符串包含搜索的字符串;否则为 false。
注解
比较不区分大小写。
strContains("ABCDEFGHIJ","abc"); //Returns true.
strContains("ABCDEFGHIJ","ABC"); //Returns true.
strContains("ABCDEFGHIJ","K"); //Returns false.
strStartsWith
检查文本字符串是否以另一个字符串开头。
boolean strStartsWith(str _string, str _potentialStart)
参数
| 参数 | Description |
|---|---|
| _字符串 | 要在其中搜索的原始字符串。 |
| _potentialStart | 开头的潜在字符串。 |
返回值
如果潜在的字符串是原始字符串的开头,则为 True;否则为 false。
注解
比较不区分大小写。
strStartsWith("ABCDEFGHIJ","abc"); //Returns true.
strStartsWith("ABCDEFGHIJ","ABC"); //Returns true.
strStartsWith("ABCDEFGHIJ","B"); //Returns false.
strEndsWith
检查文本字符串是否以另一个字符串结尾。
boolean strEndsWith(str _string, str _potentialEnd)
参数
| 参数 | Description |
|---|---|
| _字符串 | 要在其中搜索的原始字符串。 |
| _potentialEnd | 末尾的潜在字符串。 |
返回值
如此 如果潜在的字符串正在结束原始字符串;否则为 false。
注解
比较不区分大小写。
strEndsWith("ABCDEFGHIJ","ghij"); //Returns true.
strEndsWith("ABCDEFGHIJ","HIJ"); //Returns true.
strEndsWith("ABCDEFGHIJ","B"); //Returns false.
strLRTrim
从文本字符串中删除前导和尾部空白。
str strLRTrim(str text)
参数
| 参数 | Description |
|---|---|
| 文本消息 | 要从中删除前导和尾部空白的字符串。 |
返回值
不包含前导和尾随空格字符的指定字符串的副本。
注解
strLRTrim 函数是对 strRTrim 和 strLTrim 函数的补充。
Example
// Returns the text string "ABC-DEFG".
strLRTrim(" ABC-DEFG ");