Basic string manipulationAll standard sequence Operations (index, Shard, multiply, Judge membership, seek length, take maximum and minimum), also apply to strings. However, the string is immutable.String methodThere are too many ways to string, but here are just a few things that are particularly useful.FindThe Find method can look up a substring in a longer string, which returns the leftmost index at the position where the substring is located. If not found, returns-1>>> ' with a
:
>>> Ord ('s ')115>>> Chr (1, 115)'S'
String method
Strings are much richer than list methods, because strings are inherited from the string Module. This article only introduces some particularly useful string methods.
1. find
The find method can be used to search for a substring in a long string. it returns the leftmost index of the substring location. If no substring is found,-1 is returned.
The code is as follows:
>>> 'With a moo-
Basic string operations
All standard sequence operations (indexing, partitioning, multiplication, determining membership, length, minimum and maximum values) are also applicable to strings, as described earlier. However, note that the strings are immutable.
String method:
String fromStringThere are many methods for "inheritance" in the module. Here we only introduce some particularly useful methods.
1,Find
FindYou can search for a substring in a long string. It returns the leftmo
= string_to_test.match ("^ lets everything $ "); String to be tested:Regular ExpressionCase InsensitiveCharacter SetCharacter Set is another regular expression tool that allows you to match multiple specific characters (A or Z) and A series of characters (A to Z ). For example, if you want to test whether a string contains the word moo or boo, you can put these two characters in square brackets [] of a regular expression:Reference code:Copy codeThe C
substring is located. Returns 1 if it is not found.print ‘With a moo-moo here, and a moo-moo there‘.find(‘moo‘)返回:7(2) Join method: Strings are stitched together.print ‘/‘.join((‘ ‘,‘usr‘,‘bin‘,‘env‘))输出: /usr/bin/envps:和谷歌的guava有点像。(3) Lower method: Returns the lowercase m
var is_true = String_to_test.match ("^lets match everything$");
Test this string is not exactly the same as "lets everything", return false
var is_false = String_to_test.match ("^lets everything$");
The string to test:
Regular expressions
Ignore case
Character
A character set is another regular expression tool that allows you to match multiple specific characters (A or z) and a series of characters (A through Z). For example, if you want to test whether a string contains a word
methods. The Maketrans function is one of them, which is described later with the Translate method, and here are some useful string constantsString.digits: String containing the number 0~9String.letters: A string containing all lettersString.lowercase: A string containing all lowercase lettersString.printable: A string containing all printable charactersString.punctuation: A string containing all punctuationString.uppercase: A string containing all uppercase letters3.4.1 FindThe Find method can
in.>>> from string import Template>>> s=template (' $x. Glorious $x! ')>>> S.substitute (x= ' ssssss ')' Ssssss.glorious ssssss! '>>>If the replacement word is part of a word, then the parameter name must be enclosed in parentheses.>>> from string import Template>>> s=template ("It ' s ${x}tastic!")>>> S.substitute (x= ' fan ')"It ' s fantastic!">>>4. String methodsFind can look up substrings in a longer string. It returns the leftmost index of the location where the substring is located. Retur
, and this article only introduces some of the most useful string methods
1, find
The Find method can look up a substring in a longer string that returns the leftmost index of the substring's location and returns 1 if it is not found
Copy Code code as follows:
>>> ' with a moo-moo here, and a moo-moo
Currently, the JS framework and some development kits and library classes are as follows: dojo, scriptaculous, prototype, Yui-Ext, jquery, mochikit, mootools, moo. FX
Dojo (JS library and UI component ):
Dojo is currently the most powerful j s framework. It defines itself on its own wiki. dojo is an open-source DHTML toolbox written in JavaScript. Dojo really wants to be a "unified" toolbox. It is not only browser-level, but also ambitious. Dojo inclu
The difference between an assembly is not only the Assembly name, but also the assembly version, the Assembly public key, and the Assembly culture. In this article, you can set the assembly version through the interface and encoding.
□Set the assembly version Through Visual Studio
→ Right-click the project, select "properties", and select "application"→ Click "assembly information", set as follows, and click OK→ Click assemblyinfo. Cs in the properties folder of the project. You can see that
mootools
Create, more tabs are allowed in a limited width, that is, the top tab can be rolled.
Ajax tab content Block
7) AjaxTabs content script-this multi-functional AjaxTab tab content block, which allows you to display content in an external file in a div layer or the original HTML element.
Tab menu with closing capability
8) tabPanes-this is an XP-style tabs that allows you to load or close a tab in real time.
9)
Closeable
Tabs module-this can also be disabled, but no function can be en
Like the in operator, when the forin operator is used to traverse object attributes, the entire prototype chain is also traversed. Example 1:
// Poisoning Object.prototypeObject.prototype.bar = 1;var foo = {moo: 2};for(var i in foo) { console.log(i); // prints both bar and moo}
Here we should pay attention to two points. First, the for in loop will ignore the attribute set to false by enumerable. For exa
1 7462 2 9104 1 6552 2 2715 3 286Sample output1565Tips30% of the data meet: l≤n≤10 1≤m,o≤10;50% of the data meet: l≤n≤100 l≤m,o≤100;The i00% data satisfies: 1≤n≤100 1≤m,o≤1000.Casually write write, unexpectedly past, and no special do not exist, I also bother to change ... I want to eat enough.#include using namespacestd;intBest =0, Moo =-1, N, M, O;intvi[101], wi[101], si[101];voidSlove (intIintJintWints) { if(I >=N) { if(S >Best ) {
First,FJ letter matrix (moocrypt)DescriptionFew people know that cows are interested in matrices, especially the alphabet matrix. Farmer John (FJ) 's cows create a new Alphabet matrix: Find the words. For example, there is now a matrix of letters, as follows:UsopenOomaboMoomxoPqmromAs cows, they are only interested in the word "MOO". We can find 6 "MOO" in this matrix (on the same row, in the same column
using the for in loop method, which will avoid interference caused by the extension of the prototype object. Let's take a look at the example below:
// Modify the Object. prototypeObject. prototype. bar = 1; var foo = {moo: 2}; for (var I in foo) {console. log (I); // two output attributes: bar and moo}
We cannot change the behavior of the for in statement. to filter the results, we can only use the hasOwn
: public class yoo{external calls:Class moo{}----------Moo Moo=yoo.new moo ();}Local inner classDeclaring a class in a method is a local inner class, scoped like a local variableIn a method of a local inner class, such as to access the properties of an external class, it must be a final decorated constantAnonymous inne
One, string formatting, put a string on the left side, and the right place the value you want to format.' hello,%s,%s enough for ya? '>>> values = ('World','hot') print format% for ya?' %s plus%s equals%s ' % (#) # If the tuple that needs to be converted exists as part of the transformation expression, enclose it in parentheses. '1 plus 2 equals 3'1. Simple conversion' Price of eggs: $%d ' %'price ofeggs: $42'2. Field width and accuracy from Import Pi ' %10.2f ' % pi # character
First example:
Poisoning Object.prototype
Object.prototype.bar = 1;
var foo = {Moo:2};
for (var i in foo) {
console.log (i);//Prints both bar and Moo
}
Here we pay attention to two points, one for the in loop ignores the enumerable set to false. For example, the length property of an array. Second, because for-in will traverse the entire prototype chain, it can affect performance when the pro
hasownproperty function to get the correct result.
var foo = {
hasownproperty:function () {return
false;
},
bar: ' Here is Dragons '
};
Foo.hasownproperty (' Bar '); Always returns false
//using the hasOwnProperty of the {} object and setting it up to Foo
{}.hasownproperty.call (foo, ' Bar ');//True
hasOwnProperty is the only available method when checking for the existence of a property on an object. At the same time, when traversing an object using a for-in loop, the reco
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.