Copy to ClipboardReference: [www.bkjia.com] <Head>
<Title> connection string </title>
</Head>
<Body>
<Script type = "text/javascript">
Var str1 = "Javascript string connection" + ", method 1 ";
Var str2 = "method 2 ";
Str2 + = "use + = connection ";
Var str3 = "method 3 ";
Str3 + = ", multi-string connection" + ". Use multiple characters to connect" + "at the same time. Correct! ";
Var str4 = "string connection ";
Str4 = str4.concat ("use concat function connec string ");
Window. alert (str1 );
Window. alert (str2); window. alert (str3); window. alert (str4 );
</Script>
</Body>
<Html>
SEARCH strings
Locate the position of a string
Str. indexOf (subStr)
Str indicates the specified string. subStr indicates the substring to be searched.
Search for characters at a specified position
Str. charAt (n) str indicates the string to be searched. n indicates the position where the data type is integer.
Var str1 = "JSstr"; window. alert (str1.charAt (3 ));
Determine the final position of the string
Var n = str. lastindexOf (argStr );
Instance:
Copy to ClipboardReference: [www.bkjia.com] <Head>
<Title> string SEARCH </title>
</Head>
<Body>
<Script type = "text/javascript">
Var str1 = "JSStr ";
Window. alert (str1.lastindexOf ("S "));
Window. alert (str1.lastindexOf ("str "));
Window. alert (str1.indexOf ("S "));
Window. alert (str1.indexOf ("Str "));
</Script>
</Body>
<Html>
Splits a string into arrays.
Var arry = str. split (s );
The parameter s is a delimiter or a separator.
How to Use the function split:
Copy to ClipboardReference: [www.bkjia.com] var str1 = "Tom ";
Str1 + = ", Jerry, Jhon, Sqm, qqqq ";
Var strArry = new Arry ();
StrArry = str1.split (",");
For (var I = 0; I <strAry. length; I ++)
{
Window. alert (strAry [I]);
}
Truncates a string.
Var str2 = str1.substring (begin [, end]);
This method is similar to the function of intercepting a string.
Var str2 = str1.slice (begin, [, end]);
Str1 indicates the position from which the bengin string is intercepted by str2. Optional. If the end parameter is not selected, it is truncated to the end of the string.