Description:
The first two functions in the following function take out the first and last parts of the lookup string for use in other functions. Note that once the replacestring (MAINSTR,SEARCHSTR,REPLACESTR) function is invoked, only one
First look at the introduction in MSDN
Replace method
Returns the copy of a string that is replaced with text based on a regular expression.
Stringobj.replace (Rgexp, ReplaceText)
Parameters
Stringobj
Required option. The string object or
The first time you found the Replace () method in JavaScript is to use the Str.replace ("-", "!") directly. Only the first matching character will be replaced. and Str.replace (/-/g, "!") You can replace all the matching characters (G is the global
The sample code is as follows: [Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]It only replaces the first letter. However, if you add a regular expression, the results will be different! Replace (
Syntax format:UPDATE table nameSET field name = REPLACE (The field value before replacement,'Replace the previous keyword ','Keyword after replacement')WHEREField name REGEXP "replacing the previous field value ";Demo:(1) replace the content field
You have a large function where the use of local variables makes it impossible to use the extract method (extraction function ).Put this large function into a single object, so that local variables become fields in the object. Then you can break
ReinforcementJavascriptThe basic knowledge is intended for future researchJqueryThe source code paves the way.
I recently reviewedJavascriptData, found a function:
Function Format (s) {var ARGs = arguments; var pattern = new Regexp ("% ([1-
The string built-in function Replace (Regexp, newstring) of JavaScript provides the string replacement function. From the function prototype, we can see that regular exp is supported. This function is very practical, but there are also a few
SQL statement:
The code is as follows
Copy Code
UPDATE table_name Set Field_name=replace (field_name, ' from_str ', ' to_str ')
Descriptiontable_name--the name of the tablefield_name--Field Namefrom_str--a
Introduction to Usage
REPLACE (char, search_string [, replacement_string])
Char: String to wait for replacement
Search_string: Search for strings to replace
Replacement_string: Replacement string
If replacement_string is either default or null,
The parameter replacement of the replace () method can be a function rather than a string. In this case, each match calls the function, and the string it returns is used as the replacement text. The first parameter of the function is a string that
REPLACE
Replaces all occurrences of the second given string expression in the first string expression with the third expression.
Grammar
REPLACE (' String_replace1 ', ' string_replace2 ', ' string_replace3 ')
Parameters
"' String_replace1 '"
Definitions and usage
Stringobject.replace (regexp/substr,replacement)
The replace () method replaces some characters in a string with some other characters, or replaces a substring that matches a regular expression.
Look at an example
function fn ()
{
for (var i = 0;i Alert ("First" + (i+1) + "value of parameter:" +arguments[i]);
}
}
var str = ' {ni} ';
Str.replace (/{([a-z]+)}/ig, FN);
The first parameter is a matching string, such as {wo} and {ni};
The second
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).
Values char (' ABCD ', ' A ', ' OPMN ') returns the result of OPMNBCDUpdate EMP Set Name=replace (name, ' D ', ' W ') where empno=70The key to the use of this function is case-sensitive, there can be no space between the strings, otherwise it cannot
The sample code is as follows:
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
It replaces only the first letter. But if you add regular expressions, the results are different!
Today, my colleague asked me a question about the substitution of JavaScript, and he had a string "" and wanted to use "!" To replace the "
Such as:
Found the data to find that the use of regular expressions can solve this problem
There are
Word is very powerful in finding and replacing features that can be used to solve a lot of problems in editing a document. Below, we introduce the application of this function through four examples.
Task one, bulk set font format
Task requirements:
A user-defined function is a block of code stored in a database that can be returned to the calling program. Called as a system function, such as the max (value) function, where value is called a parameter. There are 3 types of function arguments.In
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.