UDN
Search public documentation:
StringsInUnrealScript
日本語訳
中国翻译
한국어
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
UE3 Home > UnrealScript > Strings In UnrealScript
Strings In UnrealScript
Overview
Operators
$ (dollar sign)
string $ ( coerce string A, coerce string B )
$
operator takes two strings, A and B, and concatenates them. If either A or B are not strings, their values will attempt to be converted to string values.
Example:
`log("Unreal"$"Script"); //prints "UnrealScript"
$=
string $= ( out string A, coerce string B )
$=
operator takes two strings, A and B, concatenates them, and assigns the resulting string to the first. If B is not a string, its value will attempt to be converted to a string value.
Example:
MyString = "Unreal"; MyString $= "Script"; // MyString contains "UnrealScript"
@ (at)
string @ ( coerce string A, coerce string B )
@
operator takes two strings, A and B, and concatenates them placing a space between the two. If either A or B are not strings, their values will attempt to be converted to string values.
Example:
log("Unreal"@"Engine"); //prints "Unreal Engine"
@=
string @= ( out string A, coerce string B )
@=
operator takes two strings, A and B, concatenates them placing a space between the two, and assigns the resulting string to the first. If B is not a string, its value will attempt to be converted to a string value.
Example:
MyString = "Unreal"; MyString @= "Engine"; // MyString contains "Unreal Engine"
< (less-than)
bool < ( string A, string B )
("Monkey" < "Robot") //this is TRUE.
> (greater-than)
bool > ( string A, string B )
("Batman" > "Aquaman") //this is TRUE.
<= (less-than-or-equal-to)
bool <= ( string A, string B )
("Monkey" <= "Robot") //this is TRUE. ("Monkey" <= "Monkey") //this is TRUE.
>= (greater-than-or-equal-to)
bool >= ( string A, string B )
("Monkey" >= "Robot") //this is FALSE. ("Monkey" >= "Monkey") //this is TRUE.
== (equal-equal)
bool == ( string A, string B )
("Monkey" == "Robot") //this is FALSE. ("Monkey" == "Monkey") //this is TRUE. ("Monkey" == "monkey") //this is FALSE.
!= (not-equal)
bool != ( string A, string B )
("Monkey" != "Robot") //this is TRUE. ("Monkey" != "Monkey") //this is FALSE. ("Monkey" != "monkey") //this is TRUE.
~= (tilde-equal)
bool ~= ( string A, string B )
("Monkey" ~= "Robot") //this is FALSE. ("Monkey" ~= "Monkey") //this is TRUE. ("Monkey" ~= "monkey") //this is TRUE.
-= (minus-equal)
string -= ( out string A, coerce string B );
MyString = "test: this is a test"; MyString -= "test"; log(MyString); // prints: ": this is a ";
Object Functions
Len
int Len ( coerce string S )
Len("this"); //returns 4;
InStr
int InStr ( coerce string S, coerce string t )
InStr("These PANTS rock!", "PANTS"); //returns 6 InStr("These PANTS rock!", "pants"); //returns -1 InStr( Caps("These PANTS rock!"), Caps("pants") ); //returns 6
Mid
string Mid ( coerce string S, int i, optional int j )
S
by starting at character i
and copying j characters. If j is omitted, the rest of the string is copied. i is clamped between 0 and the length of the string. j is clamped between i and the length of the string. If S is not a string, its value will attempt to be converted to a string value.
Example:
Mid("These PANTS rock!", 6, 5); //returns "PANTS" Mid("These PANTS rock!", 6); //returns "PANTS rock!"
Left
string Left ( coerce string S, int i )
Left("These PANTS rock!", 5); //returns "These"
Right
string Right ( coerce string S, int i )
Right("These PANTS rock!", 5); //returns "rock!"
Caps
string Caps ( coerce string S )
Caps("wooo"); //returns "WOOO"
Locs
string Locs ( coerce string S )
Locs("WoOo"); //returns "wooo"
Chr
string Chr ( int i )
Chr(65); //returns "A"
Asc
int Asc ( string S )
Asc("A"); //returns 65
Repl
string Repl ( coerce string Src, coerce string Match, coerce string With, optional bool bCaseSensitive )
Repl("This is a test", "is", "was"); // produces "Thwas was a test"; Repl("Two be or not two be", "two", "to", true); // returns "Two be or not to be" Repl("Two be or not two be", "two", "to", false); // returns "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); // returns "scripting language" Split("Unreal Engine uses UnrealScript as its scripting language", "scripting", true); // returns " language"
GetRightMost
string GetRightMost( coerce string Text )
GetRightMost("CoverLink_45"); // returns "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); // Maps contains {Deck, Necropolis, , Sanstorm, Sanctuary} ParseStringIntoArray("Deck,Necropolis,,Sandstorm,Sanctuary", Maps, ",", true); // Maps contains {Deck, Necropolis, Sanstorm, Sanctuary}
SplitString
array<string> SplitString( string Source, optional string Delimiter=",", optional bool bCullEmpty )
SplitString("Deck,Necropolis,,Sandstorm,Sanctuary", ",", false); // returns array of {Deck, Necropolis, , Sanstorm, Sanctuary} ParseStringIntoArray("Deck,Necropolis,,Sandstorm, Maps, ",", false); // Maps contains {Deck, Necropolis, , Sanstorm, Sanctuary}
Actor Functions
ReplaceText
function ReplaceText(out string Text, string Replace, string With)
Str = "This is a test"; ReplaceText(Str, "is", "was"); // Str contains "Thwas was a test"; Str = "Two be or not two be"; ReplaceText(Str, "two", "to"); // Str contains "Two be or not to be"
GetItemName
String GetItemName( string FullName )
GetItemName(string(self)); // returns the class name GetItemName("Package.Group.bla.Item"); // return "Item"
Special Considerations
String Concatenation and Assignment
You'll often see script code that looks like this: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];
- Evaluate the left side; look up the address for the
MyString
variable. - Evaluate the right side; invokes the + operator (
execString_Concat
) - Look up the address of the
MyString
variable; copy its value into a temporary buffer for use by the + operator. - Look up the address of the
NextArrayValue
(execArrayElement
); copy its value into a temporary buffer for use by the + operator. - Add the two temporary buffers together; copy that string into
MyString
.
MyString $= NextArrayValue[i];
- Look up the address for the
MyString
variable. - Look up the address for the
NextArrayValue[i]
variable. Append the value directly toMyString
.