Strings
Introduction
Strings can be enclosed using single or double quotes.
var x = "length";
To insert special characters in the string, use the backslash (\).
- \' for single quote.
- \" for double quote.
- \\ for backslash.
String Methods
lengthIt return the string length.
var BodyName = "Shaft";
var len = BodyName.length;
Output
len value is 5.
search()
To search a string and returns the position of the match.
var BodyName="Left Shaft Right Shaft";
var pos = BodyName.search("Shaft");
Output
pos value is 6.
Extracts a part of a by giving start and end position as the input.
This example slices out a portion of a string from position 8 to position 13(14-1).
var str = "This is SIMLAB";
var outputStr= str.slice(8, 14);
Output
outputStr value is "SIMLAB".
This method is used to replace one string values from another strings.
var str = "Body Name";
var outputStr = str.replace("Body", "Group");
Output
outputStr value is Group Name.
concat()
To join more than one string.
var text1 = "Mesh";
var text2 = "Size";
var text3 = text1.concat("_", text2);
Output
text3 value is Mesh_Size.
To convert into uppercase.
toLowerCase()To convert into lower case.
trim()It removes whitespace from both sides of a string.