String

Source: Internet
Author: User

Label:

String is mainly used for programming, concept description, Function interpretation, usage detailed see the text, here Add two points: 1. The ansistring in Free Pascal can only be considered as a whole, many functions can not be used, even if it is difficult to extract a single element, so unless it is absolutely impossible to use; 2. The string is stored on a similar character array, so that every single element of it can be extracted, such as s= " Abcdefghij ", then s[0]=" a ", s[9]=" J ", while the string of 0 bits is exactly its length, such as s[0]=10 (※ The above function ansistring not. , which can provide us with a lot of convenience, such as high-precision operation when each bit can be converted into a number of arrays.

Introduction
A string or series (string) is a string of characters consisting of numbers, letters, and underscores. Generally credited as s= "A1A2 An "(n>=0). It is the data type that represents the text in the programming language. In programming, a string is a sequential sequence of symbols or values, such as a string of symbols (a string of characters) or a binary number string (a string of binary digits). It usually takes the whole of a string as an operand, such as finding a substring in a string, fetching a substring, inserting a substring at a certain point in a string, and deleting a substring. The necessary and sufficient conditions for the equality of two strings are equal lengths, and the characters at each corresponding position are equal. Set P, Q is two strings, q in P in the first occurrence of the position of the operation is called pattern matching. The two most basic types of storage for strings are sequential storage and link storage.function Application
1. Connection Operation Concat (S1,S2,S3...SN) is equivalent to S1+S2+S3+...+SN. Example: Concat (' One ', ' aa ') = ' 11AA '; 2. To find a substring. Copy (s,i,i) intercepts the substring of length l after the beginning of the first character from the string s. Example: Copy (' Abdag ', 2,3) = ' BDA ' 3. Delete the substring. Procedure Delete (s,i,l) removes a substring of l after the start of the first character from the string s. Example: s:= ' ABCDE ';d elete (s,2,3); results s:= ' AE ' 4. Inserts a substring. The procedure insert (s1,s2,i) inserts the S1 into the first position of the S2 example: S:=abc;insert (' x ', s,2); result s:= ' A12BC ' 5. String length (s) Example: Length (' 12abc ') =5 in ASP for string length with Len (s) Example: Len ("Abc12") =56. Search for the location of the substring POS (S1,S2) If S1 is a substring of S2, returns the position of the first character of S1 in S2, or 0 if it is not a substring. Example: POS (' ab ', ' 12ABCD ') =37. The uppercase conversion of the character. Upcase (CH) to find the uppercase body of the character Ch. Example: UpCase (' a ') = ' a ' 8. The numeric value is converted to a string. The process str (X,S) turns the value x into several strings of S.: Str (12345,s); Results s= ' 12345 ' 9. Number of strings converted to numeric values. The process Val (s,x,i) converts several strings of s into numerical X, and if successful it is i=0, unsuccessful then I is an ordinal example of an invalid character: Val (' 1234 ', x,i); Results x:=1234virus
"String (TROJAN.STRING.A)" Virus: Alert to the extent of ¡ï ★, Trojan virus, spread through the network, relying on the system: WIN9X/NT/2000/XP. The virus spread through the network, into the user's computer is hidden in the system directory and memory, the virus attack will cause the following damage to the user's computer: The screen is empty, open the CD drive for no reason, flood attack, open the yellow website, etc., users should be careful of anti-virus.Formal theory
Set Σ is a non-empty finite set called the alphabet. The elements of Σ are called "symbols" or "characters". The string (or word) on Σ is any finite sequence from σ. For example, if σ= {0, 1}, then 0101 is a string above Σ. The length of the string is the number of characters in the string (the length of the sequence), which can be any non-negative integer. The "empty string" is the only string with a length of 0 on Σ and is indicated as ε or λ. The set of all strings of length n on Σ is indicated as Σn. For example, if σ= {0, 1} is Σ2 = {00, 01, 10, 11}. Note Σ0 = {ε} for any Alphabet Σ. The collection of all strings of any length on Σ is the kleene closure of Σ and is indicated as σ *. According to Σn,. For example, if σ= {0, 1} then σ * = {ε, 0, 1, 00, 01, 10, 11, 000, 001, 010, 011, ...}. Although the σ * itself is infinitely infinite, all elements of the σ * have a finite length. The set of strings on σ (which is any subset of σ *) is called the formal language on σ. For example, if σ= {0, 1}, then a collection of strings with an even number of zeros ({ε, 1, 00, 11, 001, 010, 100, 111, 0000, 0011, 0101, 0110, 1001, 1010, 1100, 1111, ...}) is the formal language on Σ.Threaded substring
"Threaded Connection" is an important two-dollar operation on Σ *. For the two strings in Σ * s and T, their thread is defined as the sequence of characters in S followed by the character sequence in T, and is indicated as St. For example, σ= {A, B, ..., z}, and S = bear and t = hug, then St = bearhug and ts = hugbear. String strings are associative, but non-commutative operations. An empty string acts as a unit; for any string s, there is Εs = sε= S. Therefore, the set σ * and the serial connection operation form the unitary semigroups, which is the free unitary semigroups generated from Σ. In addition, the length function defines the homogeneous state of the unitary semigroups from σ * to nonnegative integers. The string s is called the "substring" or "factor" of the string T, if present (possibly empty) the string u and V makes t = usv. The "is its substring" relationship defines the partial order on the σ *, and its minimum element is an empty string.Dictionary Sort
It is often necessary to define the order on the collection of strings. If the character descriptor Σ has a full order (cf. alphabetical order), then it can be defined as the whole order of the dictionary order on the σ *. Note that because Σ is finite, it is always possible to define the good order in σ and then on the σ *. For example, if σ= {0, 1} and 0 < 1, then σ * 's dictionary order is ε< 0 < xx < 0110 < ... < 011 < The < ... < 01111 < ... < 1 < < < ... < 101 < ... < 111 ...arithmetic
Some extra operations on strings are often present in formal theory. They are given in the entry string operation.Data type
The string data type is the data type that is modeled on the idea of the form string. Strings are very important and useful data types that can be implemented in almost all programming languages. In some languages they can be obtained as a base type and in other languages as composite types. The syntax of most high-level languages allows strings that are typically referenced in some way to represent instances of string data types, which are called "text" or "string literals."length
Although the form string can have any (but limited) length, the length of the actual language string is often limited to an artificial maximum value. Generally speaking, there are two types of string data types: "Fixed length string", which has a fixed maximum length and the same amount of memory regardless of whether it reaches this maximum value, and "variable length string", its length is not arbitrary fixed and depends on the actual size of the use of a variable amount of memory. Most strings in modern programming languages are variable-length strings. In spite of this name, all variable length strings have a limit in length, which is generally said to depend only on the amount of memory available.character encoding
Historically, the string data type allocates one byte for each character, although the exact character set changes with the region, the character encoding is similar enough that the programmer can ignore it-the set of character sets that the same system uses in different regions either let a character in the same place, or it doesn't. These character sets are typically based on ASCII code or EBCDIC code. The language of the Italian text, such as Chinese, Japanese, and Korean (collectively called CJK), requires more than 256 characters (the limit of one byte encoding per character). A general resolution involves maintaining a single-byte representation of the ASCII code and using double-byte to represent CJK glyphs. Existing code uses them to cause problems with string matching and disconnection, depending on how the character encoding is designed. Some encodings, such as the EUC family, guarantee that byte values within the ASCII range represent only ASCII characters, making it safe to encode systems that use these characters as field separators. Other encodings such as ISO-2022 and Shift-jis do not make this guarantee, making the matching of byte-based code unsafe. Another problem is that if the beginning of a string is deleted, important instructions to the decoder or information about the position in the multibyte sequence may be lost. Another problem is that if strings are concatenated (especially after the code is not known to truncate their end), the first string may not cause the encoder to enter a state that is suitable for processing the second string. Unicode also has some complex problems. Most languages have a Unicode string data type (usually UTF-16, because it is incremented before the Unicode supplemental bit surface is involved). The conversion between Unicode and native encoding requires understanding of local encoding, which is a problem for existing systems to transmit various encoded strings together without actually marking what coding they are using.Implement
Some languages, such as C + +, implement strings as templates that can be used for any base type, but this is an exception rather than a rule. If an object-oriented language represents a string as an object, they are called "mutable" (mutable), and if the value can be changed in time, it is called "unchanging" (immutable), if the value is frozen after it is established. For example, Ruby has a mutable string, whereas a Python string is immutable. Other languages, the most famous of which are Prolog and Erlang, avoid implementing string data types and instead adopt conventions that represent strings as a list of character codes.notation
A commonly used notation is an array of character codes, each of which occupies one byte (as in ASCII code) or two bytes (as in Unicode). Its length can be used with a terminator (typically the NUL,ASCII code is 0, which is used in the C programming language). Or add an integer value to indicate its length (use this method in the Pascal language). This is an example of a string ending with NUL, which is stored in 10 byte with an ASCII notation: F R A N k NUL k e F w46 4E 4 B 6B 66 66 77 The string above is 5 characters long, but note that it occupies 6 bytes. The character after the Terminator has no meaning. This is the same Pascal string: Length f R A N K k e F W05 4E 4 B 6B 66 66 77 Of course, there may be other representations. Using trees and lists can make some string operations, such as insertions and deletions, more efficient.Utility Program
Some programming languages are designed to write string handlers more easily. Here are some examples: Awkiconperlmumpssedsnobol a lot of Unix utilities for simple string processing and can be used to simply write some powerful string processing algorithms. Files and finite streams can be viewed as strings. Some new programming languages, including Perl, Python, and Ruby, use regular expressions to help with text processing.operation
A simple string operation is "connection": that is, to write a string s, and then write a T in the back to get St such a process. Other common operations include searching for a substring in a long string, arranging a set of strings, and parsing a string. Because there are so many ways to apply strings, there are a number of related algorithms that weigh the different applications accordingly. Advanced string algorithms typically use complex mechanisms and data structures, including back-tree and finite-state machines.algorithm
Here are some string processing algorithms that perform different processing on strings: string lookup algorithm Regular expression algorithm pattern matching string matching algorithm (KMP) AC automataintroduced in PHP
String is a series of characters. In PHP, the characters and bytes, that is, a total of 256 different characters of the possibility. This also implies that PHP does not have local support for Unicode. See Functions Utf8_encode () and Utf8_decode () to learn about Unicode support Note: A string becomes very large and no problem, PHP does not impose a range of implementations on the size of the string, so there is absolutely no reason to worry about long strings. The syntax string can be defined in three literal ways. Single quote double quotation mark delimitersingle quotation marksThe simplest way to specify a simple string is to enclose it in single quotation marks (characters '). To represent a single quotation mark, you need to escape with a backslash (/), as in many other languages. If a backslash is required before the single quotation mark or at the end of the string, it needs to be represented by two backslashes. Note that if you try to escape any other characters, the backslash itself will be displayed as well! Therefore, it is usually not necessary to escape the backslash itself. Note: In PHP 3, this situation will issue a e_notice level warning. Note: Unlike the other two syntaxes, the variables and escape sequences that appear in the single-quote string won'tReplaced by the value of the variable. <?phpecho ' This was a simple string '; Echo ' can also has embedded newlines instrings this "as it isokay to do ';/ Outputs:arnold once said: "I'll be Back" Echo ' Arnold once said: "I/' ll is back" ';//outputs:you deleted C:/*.*?echo ' Yo U deleted c://*.*? '; /outputs:you deleted C:/*.*?echo ' you deleted c:/*.*? '; /Outputs:this would not expand:/n A Newlineecho ' this would not expand:/n a newline ';//outputs:variables do not $expan D $eitherecho ' Variables do not $expand $either ';? > Also, if you try to escape any other characters, the backslash itself will be displayed! The most important point of a double-quote string is that the variable name is substituted by the value of the variable. See string parsing for details.delimiterAnother way to set the bounds of a string is to use the delimiter syntax ("<<<"). You should provide an identifier after <<<, followed by a string, followed by the same identifier end string. End identifier must beStart with the first column of the row. Similarly, identifiers must follow the naming conventions of any other tag in PHP: They can only contain alphanumeric underscores, and must begin with an underscore or non-numeric character. Example 11-3. Illegal example <?phpclass Foo {public $bar = <<<eotbareot;}? > delimiter text behaves just like a double-quoted string, with no double quotes. This means that you do not need to escape quotes in the delimiter text, but you can still use the escaped code listed above. Variables are expanded, but when you express complex variables in the delimiter text, you should be aware of the same as the string. Example 11-4. Delimiter String Example <?php$str = <<<eodexample of stringspanning multiple linesusing heredoc syntax. eod;/* more complex example, with variables. */class foo{var $foo; var $bar; function foo () {$this->foo = ' foo '; $this->bar = Array (' Bar1 ', ' Bar2 ', ' Bar3 ');} } $foo = new Foo (), $name = ' MyName '; Echo <<<eotmy name is "$name". I am Printing some $foo->foo. Now, I am printing some {$foo->bar[1]}. This should print a capital ' a ':/x41eot;? > Note: The delimiter support is added in PHP 4.Variable ResolutionWhen you specify a string with double quotation marks or delimiters, the variables are parsed. There are two kinds of syntax, one simple and one complex. Simple syntax is the most versatile and convenient, and it provides methods for parsing variables, array values, or object properties. The complex syntax is introduced in PHP 4, and you can enclose an expression in curly braces. Simple syntax if you encounter a dollar sign ($), the parser will get as much of the following word utilises as possible to make up a valid variable name. If you want to explicitly specify the end of the name, enclose the variable name in curly braces. <?php$beer = ' Heineken '; echo "$beer ' s taste is great"; Works, "'" is a invalid character for Varnamesecho "He drank some $beers"; Won ' t work, ' s ' are a valid character for Varnamesecho "He drank some ${beer}s"; Worksecho "He drank some {$beer}s"; Works?> can also parse array indexes or object properties. For an array index, the closing bracket (]) marks the end of the index. Object properties apply the same rules as simple variables, although there are no small tricks like variables for object properties. <?php//These examples is specific to using arrays inside of strings.//when outside of a string, always quote your AR Ray string keys//and do no use {braces} when outside of strings either.//let's Show All Errorserror_reporting (E_all); $f ruits = Array (' Strawberry ' = ' red ', ' banana ' = ' yellow ');//Works but note the this works differently outside Str Ing-quotesecho "A banana is $fruits [banana]."; /Worksecho "A Banana is {$fruits [' banana ']}."; /Works BUT PHP looks for a constant named Banana first//as described Below.echo "a banana is {$fruits [banana]}."; /Won ' t work, use braces. This results in a parse Error.echo "a banana is $fruits [' banana ']."; /Worksecho "A banana is". $fruits [' Banana ']. ".";/ /Worksecho "This square is $square->width meters broad."; /Won ' t work. For a solution, see the complex Syntax.echo "This square is $square->width00 centimeters broad."? > For any more complex situation, you should use complex syntax. Complex (curly brace) syntax is not complicated by syntax, but because it can contain complex expressions. In fact, use this syntax to include any value in the namespace in the string. Simply write an expression with the same method as the string, and then include it with {and}. Because "{" cannot be escaped, this syntax is recognized only after the {"{/$" or "/{$" to get a literal "{$"). Some examples can be clearer: <?php//Let's show All Errorserror_reporting (E_all); $great = ' fantastic ';//No, output: This is {fantastic} echo "This is {$great}";//Can be output as: This is Fantasticecho "the is {$great}"; echo "This Is ${great}";//Worksecho "This squ Was is {$square->width}00 centimeters broad. "; /Worksecho "This works: {$arr [4][3]}",//This was wrong for the same reason as $foo [bar] is wrong//outside a string. In otherwords, it'll still work but//because PHP first looks for a constant named Foo, it will//throw an error of leve L E_notice (undefined constant). echo "This is wrong: {$arr [foo][3]}";//Works. When using the multi-dimensional arrays, always use//braces around arrays when inside of Stringsecho "This works: {$arr [' foo ' ][3]} ";//Works.echo" This Works: ". $arr [' foo '][3];echo "You can even write {$obj->values[3]->name}", echo "This is the value of the Var named $name: {${ $name}} ";? > Accessing and modifying Characters in a character string in a string can be accessed and modified by specifying the zero-based offset of the desired character with curly braces after the string. Note: In order to be backwards compatible, square brackets can still be used. However, this syntax is obsolete since PHP 4. Example 11-5. Some examples of strings <?php//Get the first character of a string$str = ' This is a test. '; $first = $str {0};//Get the third character of a string$third = $str {2};//Get the last character of a string. $str = ' This is still a test. '; $last = $str {strlen ($str) -1};//Modify The last character of a string$str = ' Look at the sea '; $str {strlen ($STR)-1} = ' E ';? >Utility FunctionsStrings can be used with "." (dot) operator connection. Note that the "+" operator cannot be used here. For more information, see string Operators. There are many useful functions to change a string. For general functions, see the String Functions section, advanced search and replace see Regular expression functions (two styles: Perl and POSIX extensions). There are also URL string functions, as well as functions for encrypting/decrypting strings (MCrypt and Mhash). Finally, if you still can't find the function you want, see the character type function.ConversionYou can use the (string) tag or the Strval () function to convert a value to a string. When a string is required for an expression, the conversion of the string is done automatically within the scope of the expression. For example, when you use the Echo () or print () function, or when you compare a variable value to a string. Reading the manuals in the section on types and type tricks helps to be clearer. See Settype (). [1] Boolean true will be converted to the string "1", and the value false will be expressed as "" (that is, an empty string). This allows you to randomly compare a Boolean value to a string. When a numeric value of an integer or floating-point number is converted to a string, the string consists of numeric characters representing the numbers (the floating-point number also contains the exponential portion). The array is converted to the string "array", so the contents of the array cannot be output through the echo () or print () function. Please refer to below for more tips. The object is converted to the string "Object". If you need to print the object's member variables for debugging purposes, please read the following. If you want to get the name of the class to which the object is attached, use the function Get_class (). From PHP 5, if appropriate, you can use the __tostring () method. The resource type is always converted to a string in the format "Resource ID #1", where 1 is the unique identity that PHP assigns to the resource at run time. If you want to get the type of the resource, use the function Get_resource_type (). Null will be converted to an empty string. As shown above, printing arrays, objects, or resources does not provide any useful information about the values themselves. See Functions Print_r () and Var_dump (), which are better ways to print values for debugging purposes. You can convert the values of PHP to strings to store them permanently. This method is called serialization and can be done with the function serialize (). If you set up WDDX support when you install PHP, you can also serialize the value of PHP into an XML structure.Convert ValuesWhen a string is evaluated as a number, the type and value of the result are determined according to the following rules. If any one of the characters is included in ".", "E" or "E", the string is evaluated as a float. Otherwise, it is treated as an integer. The value is determined by the first part of the string. If the string starts with a valid numeric data, the number is used as its value, otherwise its value is 0 (0). Valid numeric data starts with an optional sign, followed by one or more digits (optionally including a decimal fraction) followed by an optional exponent. An exponent is an "E" or "E" followed by one or more numbers. <?php$foo = 1 + "10.5"; $foo is float (11.5) $foo = 1 + " -1.3e3"; $foo is float ( -1299) $foo = 1 + "bob-1.3e3"; $foo is integer (1) $foo = 1 + "BOB3"; $foo is integer (1) $foo = 1 + "Small Pigs"; $foo is integer $foo = 4 + "10.2 Little piggies"; $foo is float (14.2) $foo = "10.0 pigs" + 1; $foo is float (one) $foo = "10.0 pigs" + 1.0; $foo is float (one)?> for more information on this conversion, see the section on Strtod (3) in the Unix manual. If you want to test any of the examples in this section, you can copy and paste the examples and add the following line to see what happens: <?phpecho "/$foo = = $foo; Type is ". GetType ($foo). "<br/>/n";? > do not expect to be able to encode a character when converting it to an integer (which may also be done in C). If you want to convert between character encodings and characters, use the Ord () and Chr () functions. [2]

String

Related Article

Contact Us

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.

Tags Index: