Introduced
5.0
Description
JScript and other languages offer sophisticated string manipulation functions via regular expressions. However regular expressions can be a little daunting to learn. This command provides a simple solution for the common task of triming extra space characters from from the front or end of a string. To write a truly user-friend interface it is prudent to always clean input strings in this fashion.
Note: This function does not remove any tab characters (\t) or linefeeds (\n) from the string.
Scripting Syntax
TrimString( StringToTrim, [TrimLeft], [TrimRight] )
Parameters
|
Parameter |
Type |
Description |
|
StringToTrim |
Input that might contain extra white space characters |
|
|
TrimLeft |
whether to remove all leading white space Default Value: true |
|
|
TrimRight |
whether to remove all trailing white space Default Value: true |
Return Value
Examples
1. JScript Example
cleanedString = TrimString( " myname " ) ; // cleanedString will contain "myname" Application.LogMessage(cleanedString);
2. JScript Example
/* Demonstration of how JScript's regular expression functionality can be used instead of the TrimString command */ Application.LogMessage( TrimSpaces( " myname " ) ) ; function TrimSpaces( in_str ) { // Strip front and back spaces // (also cleans out \t and \n characters) return in_str.replace(/(^\s*)|(\s*$)/g, ""); }
See Also
Autodesk Softimage v7.5