How to get the end of stings in script.
by Phil Mundy · in Torque Game Engine · 08/09/2006 (3:01 am) · 5 replies
%string = "testforcheck";
I want to test if the last 5 chars are $="check".
Any ideas?
I want to test if the last 5 chars are $="check".
Any ideas?
#2
08/13/2006 (6:04 am)
Thanks... but still a bit confused as to the commands you are suggesting to use.
#3
Something along the lines of the following should do what you want:-
08/13/2006 (6:35 am)
A good reference for script based string functions can be found on TDN tdn.garagegames.com/wiki/TorqueScript_CommandsSomething along the lines of the following should do what you want:-
%strTail = getSubStr( %string, strlen(%string)-5, 5 );
if (%strTail $= "check")
{
....
}
#4
Harold's post on string functions
TorqueScript on TDN
08/13/2006 (6:39 am)
Gary's example should work, but if it does not.. change it to this:%string = "testforcheck";
%searchString = "check";
%strTail = getSubStr( %string, ( strlen( %string ) -5 ), 5 );
if ( %strTail $= %searchString )
{
// do something here
}May I suggest two articles for you:Harold's post on string functions
TorqueScript on TDN
#5
08/13/2006 (7:48 am)
Aye, thats what I was looking for. That list of script commands is useful! I swear it wasn't there a few weeks ago! Top stuff!
Torque Owner Stefan Lundmark
Or just do a strPos and see if the position is within the last 5 from the total strLen.