UDN
Search public documentation:
StringsInUnrealScriptCH
English Translation
日本語訳
한국어
Interested in the Unreal Engine?
Visit the Unreal Technology site.
Looking for jobs and company info?
Check out the Epic games site.
Questions about support via UDN?
Contact the UDN Staff
日本語訳
한국어
Interested in the Unreal Engine?
Visit the Unreal Technology site.
Looking for jobs and company info?
Check out the Epic games site.
Questions about support via UDN?
Contact the UDN Staff
虚幻脚本中的字符串处理
概述
操作符
$(美元符号操作符)
string $ ( coerce string A, coerce string B )
$
操作符需要两个字符串, A 和 B ,然后连接它们。如果 A 或者 B 不是字符串,那么将会尝试将它们的值转换为字符串值。
示例:
`log("Unreal"$"Script"); //prints "UnrealScript"
$=
string $= ( out string A, coerce string B )
$=
操作符需要两个字符串, A 和 B ,连接它们,然后将最终的字符串分配给第一个字符串。如果 B 不是字符串,那么会尝试将它的值转换为一个字符串值。
示例:
MyString = "Unreal"; MyString $= "Script"; // MyString 包含 "UnrealScript"
@(at 符号操作符)
string @ ( coerce string A, coerce string B )
@
操作符需要两个字符串, A 和 B ,然后连接它们,在它们两个之间放置一个空格。如果 A 或者 B 不是字符串,那么将会尝试将它们的值转换为字符串值。
示例:
log("Unreal"@"Engine"); //prints "Unreal Engine"
@=
string @= ( out string A, coerce string B )
@=
操作符需要两个字符串, A 和 B ,连接它们,在它们之间放置一个空格,然后将最终的字符串分配给第一个字符串。如果 B 不是字符串,那么会尝试将它的值转换为一个字符串值。
示例:
MyString = "Unreal"; MyString @= "Engine"; // MyString contains "Unreal Engine"
<(小于号操作符)
bool < ( string A, string B )
("Monkey" < "Robot") //结果是 TRUE。
>(大于号操作符)
bool > ( string A, string B )
("Batman" > "Aquaman") //结果是 TRUE。
<=(小于或等于号操作符)
bool <= ( string A, string B )
("Monkey" <= "Robot") //结果是 TRUE。 ("Monkey" <= "Monkey") //结果是 TRUE。
>=(大于或等于号操作符)
bool >= ( string A, string B )
("Monkey" >= "Robot") //结果是 FALSE。 ("Monkey" >= "Monkey") //结果是 TRUE。
==(等号操作符)
bool == ( string A, string B )
("Monkey" == "Robot") //结果是 FALSE。 ("Monkey" == "Monkey") //结果是 TRUE。 ("Monkey" == "monkey") //结果是 FALSE。
!=(不等号操作符)
bool != ( string A, string B )
("Monkey" != "Robot") //结果是 TRUE。 ("Monkey" != "Monkey") //结果是 FALSE。 ("Monkey" != "monkey") //结果是 TRUE。
~=(约等号操作符)
bool ~= ( string A, string B )
("Monkey" ~= "Robot") //结果是 FALSE。 ("Monkey" ~= "Monkey") //结果是 TRUE。 ("Monkey" ~= "monkey") //结果是 TRUE。
-=(减法赋值操作符)
string -= ( out string A, coerce string B );
MyString = "test: this is a test"; MyString -= "test"; log(MyString); // 输出: ": this is a ";
Object 函数
Len
int Len ( coerce string S )
Len("this"); //返回 4;
InStr
int InStr ( coerce string S, coerce string t )
InStr("These PANTS rock!", "PANTS"); //返回 6 InStr("These PANTS rock!", "pants"); //返回 -1 InStr( Caps("These PANTS rock!"), Caps("pants") ); //返回 6
Mid
string Mid ( coerce string S, int i, optional int j )
S
的字符 i
开始复制 j 个字符来生成一个 S
的子字符串。 如果省略了 j ,那么将会复制所有的剩余字符串。 i 的值在 0 到字符串长度的区间限定之间。 j 的值在 i 到字符串长度的区间限定内。如果 S 不是字符串,那么会尝试将它的值转换为一个字符串值。
示例:
Mid("These PANTS rock!", 6, 5); //返回 "PANTS" Mid("These PANTS rock!", 6); //返回 "PANTS rock!"
Left
string Left ( coerce string S, int i )
Left("These PANTS rock!", 5); //返回 "These"
Right
string Right ( coerce string S, int i )
Right("These PANTS rock!", 5); //返回 "rock!"
Caps
string Caps ( coerce string S )
Caps("wooo"); //返回 "WOOO"
Locs
string Locs ( coerce string S )
Locs("WoOo"); //返回 "wooo"
Chr
string Chr ( int i )
Chr(65); //返回 "A"
Asc
int Asc ( string S )
Asc("A"); //返回 65
Repl
string Repl ( coerce string Src, coerce string Match, coerce string With, optional bool bCaseSensitive )
Repl("This is a test", "is", "was"); // 会产生 "Thwas was a test"; Repl("Two be or not two be", "two", "to", true); // 返回 "Two be or not to be" Repl("Two be or not two be", "two", "to", false); // 返回 "to be or not to be"
Split(分隔)
static final function string Split(coerce string Text, coerce string SplitStr, optional bool bOmitSplitStr)
Split("Unreal Engine uses UnrealScript as its scripting language", "scripting", false); // 返回 "scripting language" Split("Unreal Engine uses UnrealScript as its scripting language", "scripting", true); // 返回 " language"
GetRightMost
string GetRightMost( coerce string Text )
GetRightMost("CoverLink_45"); // 返回 "45"
JoinArray
JoinArray(array<string> StringArray, out string out_Result, optional string delim = ",", optional bool bIgnoreBlanks = true)
Maps[0] = "Deck"; Maps[1] = "Necropolis"; Maps[2] = "Sandstorm"; Maps[2] = "Sanctuary"; JoinArray(Maps, MapString); // MapString contains "Deck,Necropolis,Sandstorm,Sanctuary"
ParseStringIntoArray
ParseStringIntoArray(string BaseString, out array<string> Pieces, string Delim, bool bCullEmpty)
ParseStringIntoArray("Deck,Necropolis,,Sandstorm,Sanctuary", Maps, ",", false); // 地图包含 {Deck, Necropolis, , Sanstorm, Sanctuary} ParseStringIntoArray("Deck,Necropolis,,Sandstorm,Sanctuary", Maps, ",", true); // 地图包含 {Deck, Necropolis, Sanstorm, Sanctuary}
SplitString
array<string> SplitString( string Source, optional string Delimiter=",", optional bool bCullEmpty )
SplitString("Deck,Necropolis,,Sandstorm,Sanctuary", ",", false); // 返回 {Deck, Necropolis, , Sanstorm, Sanctuary} 的数组 ParseStringIntoArray("Deck,Necropolis,,Sandstorm, Maps, ",", false);// 地图包含 {Deck, Necropolis, , Sanstorm, Sanctuary}
Actor 函数
ReplaceText
function ReplaceText(out string Text, string Replace, string With)
Str = "This is a test"; ReplaceText(Str, "is", "was"); // Str 包含了 "Thwas was a test"; Str = "Two be or not two be"; ReplaceText(Str, "two", "to"); // Str 包含了 "Two be or not to be"
GetItemName
String GetItemName( string FullName )
GetItemName(string(self)); // 返回这个类名称 GetItemName("Package.Group.bla.Item"); // 返回 "Item"
特殊注意事项
字符串连接和赋值
您经常看到类似于以下的脚本代码:for ( i = 0; i < Count; i++ ) { if ( MyString != "" ) { MyString = MyString + ", "; } MyString = MyString + NextArrayValue[i]; }
native(322) static final operator(44) string $= ( out string A, coerce string B ); native(323) static final operator(44) string @= ( out string A, coerce string B);
for ( i = 0; i < Count; i++ ) { if ( MyString != "" ) { MyString $= ", "; } MyString $= NextArrayValue[i]; }
MyString = MyString + NextArrayValue[i];
- 计算左侧;查找
MyString
变量的地址。 - 计算右侧;激活 + 操作符 (
execString_Concat
) - 查找
MyString
变量的地址;通过 + 操作符把它的值复制到临时缓存中以便使用。 - 查找
NextArrayValue
(execArrayElement
) 的地址;通过 + 操作符把它的值复制到临时缓存中以便使用。 - 将两个临时缓存加到一起;并将该字符串复制到
MyString
中。
MyString $= NextArrayValue[i];
- 查找
MyString
变量的地址。 - 查找
NextArrayValue[i]
变量的地址。直接将该值附加到MyString
上。