Common javascript string functions
The most common string methods are: indexof (), charat (), and substring ()Indexof () function:
This function allows you to determine whether a string exists in a longer string and its location. It is equivalent to the strstr function in C
In JavaScript, we are often exposed to the 5 more special objects mentioned in the topic-false,0, empty strings ,null , and undefined . These objects are easy to use, so you have to be careful when you use them.Type detectionLet's come down and see what their type is:
Running the above code, the dialog box that pops up should display true. That is,false is a Boolean type object, 0 is a numeric type object, an empty
Both PHP and JavaScript are beginners. There is a recent need:
Let's say there's a multi-line string for PHP:
$a =
After passing to JavaScript is equivalent to:
var c= ' thy38\n\ csdn\n\ blog ';
Because the understanding of these two languages is low to do not know how Google, had to find out the method of two ways:
1. First escape PHP, then split, then
Example of getting started with the JavaScript indexOf method (calculate the position where the specified character first appears in the string), javascriptindexof
JavaScript indexOf Method
The indexOf method is used to calculate the position where a specified string first appears in a
For a ExtJS extension to a string in JavaScript, refer to its Help documentation, document: http://download.csdn.net/detail/z1137730824/7748893Some of these methods are described below:(1) CapitalizeCapitalize (String String): StringReturns a string in which the first letter
represented by the value of the bit, which is referred to asCode Unit. The advantage of this representation is that theUnicodethe index operation of a string can be done in constant time, because all characters are -bit, i.e.2bits of the expression. because of the convenience of this coding method, some platforms such as Java , JavaScript have adopted it. As a result,each character of aJavaScript
Document directory
Enter:
Because the replaceall () method is not provided in Javascript, it is not very comfortable to use. Next I will show you how to use the replace method to obtain columns with other effects, such as the replaceall effect.
String. Replace ()
Syntax:
string.replace(regexp, replacement)
Regexp: the regular expression of the replacement operation. If a
Note: When I was reading ES5 two days ago, I came up with a question. Today I saw this article, but I just explained it clearly and translated it.In JavaScript, there are three main ways to convert any value into a string. This article describes each method and its advantages and disadvantages.
1. Three Methods to convert stringsThe three methods to convert values to strings are:
1. value. toString ()2. ""
Note: When I was reading ES5 two days ago, I came up with a question. Today I saw this article, but I just explained it clearly and translated it.In JavaScript, there are three main ways to convert any value into a string. This article describes each method and its advantages and disadvantages.1. Three Methods to convert stringsThe three methods to convert values to strings are:1. value. toString ()2. "" +
This article mainly introduces how to judge string inclusion in javascript. It can effectively detect whether a string contains fixed characters or substrings. It involves the use of indexOf in javascript and is very simple and practical, for more information about how to use JavaS
Defined:The way to define a string is to assign a value directly, for example: Var mystr= "Javascript is good!";
To access the properties of a string:
Length Property
Eg:var myl=mystr.length;//The myl length is 19 (spaces, symbols to be counted in, the end of the same as the C language and there is a null for a bit)
Ways to access string
The core of JavaScript is ECMAScript. Similar to other languages, the strings of ECMAScript are unchangeable, that is, their values cannot be changed.
Consider the following code:
Copy codeThe Code is as follows: var str = "hello ";
Str + = "world"; in fact, the steps behind this Code are as follows:
1. Create a string that stores "hello.2. Create a string for st
String concatenation is often encountered in JavaScript, but it can be cumbersome if the string to be spliced is too long.
If on one line, the readability is too bad, if the line is changed, the error will be directly.
Here are a few tips for a few javascript concatenation strings (mainly for strings that are too l
There are 4 methods in JavaScript that involve a string case conversion: toLowerCase (), toLocaleLowerCase (), toUpperCase (), and toLocaleUpperCase (). Today we will mainly use the following touppercase () and toLowerCase () methods.
JavaScript provides two ways to convert a string to all uppercase or lowercase, so t
I recently checked the JavaScript data and found a function:
Copy Code code as follows:
function format (s)
{
var args = arguments;
var pattern = new RegExp ("% ([1-" + Arguments.length + "])", "G");
return String (s). Replace (Pattern,function (word,index) {
return Args[index];
});
}
Test
window.onload = alert (Format ("and"%1 want to know whose%2 "," Papers "," shirt ","
JavascriptString Object
A String object is used to handle an existing block of characters.
JavaScript stringA string is used to store a series of characters like "John Doe".A string can use either single or double quotation marks:Example var carname= "Volvo XC60";var carname= ' Volvo XC60 ';You use the loca
,replacement);8, used to retrieve a substring specified in a string, or to retrieve a substring that matches a regular expressionStringobject.search (RegExp);9. Can extract a part of a string and return the extracted part with a new stringStringobject.slice (Start,end);10, divides a string into the string array, separa
());//Display as superscript
charCodeAt (index) returns the Unicode encoding of the character at the index of the string, which is an integer between 0~65535 and, if the index is out of range, returns Nan.
Concat (STR2) joins the string str2 the current string into a new string.
Anchor (ANCHAR_NAME) creates
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.