虎毒不食子是什么意思| 得了甲亢都有什么症状| 什么牙什么嘴| 蛐蛐吃什么| 药食同源是什么意思| 龙马精神代表什么生肖| hcv阳性是什么意思| 黑加仑是什么水果| 下旬是什么意思| 颈椎病用什么枕头好| 冬瓜什么季节吃最好| lee是什么意思| 提刑官相当于现在什么官| 磷高了会出现什么症状| 自汗恶风是什么意思| 小孩肚脐眼周围疼是什么原因| 小儿拉肚子吃什么药好得快| 与众不同是什么意思| 腿有淤青是什么原因| 大表哥是什么游戏| 乙肝两对半挂什么科| 尿路感染吃什么药效果最好| 番茄可以做什么菜| 预警是什么意思| 关节由什么组成| 海龟吃什么| 唏嘘是什么意思| 血常规挂什么科| 什么是纯净水| 瑜伽是什么| 山药长什么样| 入定是什么意思| 感冒有黄痰是什么原因| 骑单车锻炼什么好处| 女儿红是什么| 38岁属什么| 椰子煲汤放什么材料| 经常长溃疡是什么原因引起的| 独什么心什么| 平均红细胞体积偏高是什么原因| 胃窦炎是什么原因引起的| 脚没有力气是什么原因| bg是什么意思| 优衣库属于什么档次| 晚上口苦是什么原因引起的| bp在医学上是什么意思| ms什么意思| 全血是什么意思| 一个丝一个鸟读什么| 北京市副市长是什么级别| 斗是什么样子| 山梨酸钾是什么| 什么是免疫力| rf是什么的缩写| 氯化钠是什么盐| 掉以轻心是什么意思| 牙齿松动了有什么办法能固齿吗| 眼角流泪是什么原因| 下寒上热体质吃什么中成药| 角化型脚气用什么药最好| 女人胆固醇高什么原因| 胆囊结石吃什么药| 胃肠彩超能检查出什么| 尿道感染是什么原因引起| 粉底液是干什么用的| 杏鲍菇不能和什么一起吃| 杨八妹属什么生肖| 接驳是什么意思| 女生肚子疼是什么原因| 胰是什么器官| 云南有什么少数民族| 物以类聚什么意思| xsh是什么意思| 馋肉是身体里缺什么| 7月7号是什么节日| 什么是凤凰男| 看守所和拘留所有什么区别| 紫玫瑰代表什么意思| 为什么不吃猪肉| 天珠是什么做的| 藏红花和什么一起泡水喝效果好| 二月八号是什么星座| 肉刺用什么药膏能治好| 参保是什么意思| 狗狗能看见什么颜色| 一台什么| 阳性体征是什么意思| 95年属什么生肖婚配表| 反射弧长是什么意思| 颈椎疼挂什么科室| 万圣节应该送什么礼物| 中国现在是什么社会| 天赋异禀什么意思| 荆芥是什么菜| 精子对女性有什么好处| 信的拼音是什么| 爸爸的姐姐叫什么| 二道贩子是什么意思| 知柏地黄丸主治什么| 乾隆为什么不喜欢雍正| 菜粥里面放什么菜最好| 措施是什么意思| 顺风顺水是什么生肖| 心脏主要由什么组织构成| 鸡蛋壳薄是什么原因| 胃溃疡能吃什么水果| 孕妇现在吃什么水果好| 胃胀反酸吃什么药效果好| 什么叫情商高| 七情六欲指的是什么| 原生家庭什么意思| 脊椎痛什么原因| 炖排骨什么时候放盐| 月经有黑色血块是什么原因| 吃什么卵泡长得快又好| 扁桃体发炎什么症状| 口语化是什么意思| 浑圆是什么意思| 9月19日是什么星座| 加拿大用什么货币| 柠檬是什么季节的水果| 鳄鱼的天敌是什么动物| 孕妇缺营养吃什么补| 下蛊是什么意思| 和什么细什么的成语| 氨水是什么东西| 什么是铅中毒| 脖子上长痘痘是什么原因| 火龙果和什么相克| 毫不犹豫的意思是什么| 慢性咽喉炎吃什么药好| 格列本脲和格列美脲有什么区别| 鱼豆腐是用什么做的| 蕾丝边是指什么意思| 阴囊湿疹挂什么科| 懵逼是什么意思| tf卡是什么| 脑子疼是什么原因| 你真狗是什么意思| 酸辣土豆丝用什么醋| 姜虫咬人有什么症状| 如虎添翼是什么生肖| 脱毛膏的原理是什么| 一什么红枣| 黑洞长什么样| 小孩口臭吃什么药| 防晒衣什么颜色最防晒| 什么的玉米| 脑梗吃什么药可以恢复的快| 棕色皮鞋配什么颜色裤子| durex什么意思| 手掌发红是什么病| 农历正月十五吃什么| 什么药治灰指甲最有效| 每次上大便都出血是什么原因| 阴茎硬不起来吃什么药| 额头爱出汗是什么原因| 小孩干呕是什么原因| 绿豆什么人不能吃| 中元节是什么意思| 玄牝是什么意思| 飞沙走石是什么意思| 梦见蛇是什么征兆| 白蜡金命五行缺什么| hpv是什么疫苗| 为什么会落枕| 做梦梦到怀孕了是什么意思| 梦见很多肉是什么意思| 5个月宝宝可以吃什么水果| 8月14日是什么星座| 小孩低烧吃什么药| 过敏性皮炎吃什么药好| 甲状腺什么症状| 吃什么皮肤好| 血糖高吃什么药| 黄皮什么时候成熟| 胆汁酸是什么| 李子是什么水果| 海狗是什么| pls是什么意思| 德国人是什么人种| 横批是什么意思| 七月有什么水果| 什么丝什么缕| 午未合化什么| 高考推迟月经吃什么药| 蚂蚁为什么会咬人| 公务员是做什么的| 为什么会长虱子| 补充蛋白质提高免疫力吃什么| 猴子的尾巴像什么| xmm是什么意思| 嘴唇为什么会变黑| 栩是什么意思| 知柏地黄丸治什么病| 咽炎是什么症状| 拆台是什么意思| 将军指什么生肖| 吃什么容易发胖| 喉痹是什么意思| 扇子骨是什么肉| 贫血的人来姨妈会有什么症状| 口酸吃什么药| 定量是什么意思| 松果体囊肿是什么病| 搓是什么意思| 办出国护照需要什么手续| 一个点念什么| 河粉为什么叫河粉| 高育良什么级别| 多维元素片有什么作用| 11月28是什么星座| 铜镯子对人有什么好处| 男占258女占369什么意思| 剖腹产后吃什么| 心悸心慌吃什么药| 转注是什么意思| 梦见死了人是什么征兆| 前胸后背长痘痘用什么药| maybach是什么车| 陪跑什么意思| 唯有女子与小人难养也什么意思| 痛风在医院挂什么科| 阴道有腥味是什么原因| 汕头有什么好玩的地方| 大黄泡水喝有什么功效| 数九寒天是什么意思| 乳腺应该挂什么科| 绝望的绝是什么意思| 规格是什么意思| 见路不走是什么意思| 处心积虑是什么意思| 气短咳嗽是什么原因引起的| 胸闷是什么原因引起的| 爱出汗是什么原因| 什么叫小三阳| 8月6号什么星座| 脚踝肿挂什么科| 植入是什么意思| 知柏地黄丸有什么功效| 苁蓉有什么功效| 脱线是什么意思| 狗肉炖什么好吃| 成人感冒挂什么科| 梦见房子倒塌是什么意思| 什么是ppi| scofield是什么品牌| 人为什么会做噩梦| 喉咙发炎吃什么食物好| 什么人不能喝蜂蜜| 春天有什么特点| 梦见山体滑坡是什么意思| 卡不当什么意思| 过江龙是什么意思| 生理曲度存在是什么意思| 梦见火灾预示什么| 气管憩室是什么意思| 戊日是什么意思| 上焦不通吃什么中成药| 老人吃什么钙片补钙效果最好| 发端是什么意思| 大快朵颐是什么意思| 梦见给别人钱是什么意思| 爱的最高境界是什么| 百度

76年出生属什么生肖

(Redirected from Character string)
百度 归根结底,领导干部要有一种观念自觉,通过践行绿色发展,展现自身的绿色担当。

In computer programming, a string is traditionally a sequence of characters, either as a literal constant or as some kind of variable. The latter may allow its elements to be mutated and the length changed, or it may be fixed (after creation). A string is often implemented as an array data structure of bytes (or words) that stores a sequence of elements, typically characters, using some character encoding. More general, string may also denote a sequence (or list) of data other than just characters.

Diagram of String data in computing. Shows the word "example" with each letter in a separate box. The word "String" is above, referring to the entire sentence. The label "Character" is below and points to an individual box.
Strings are typically made up of characters, and are often used to store human-readable data, such as words or sentences.

Depending on the programming language and precise data type used, a variable declared to be a string may either cause storage in memory to be statically allocated for a predetermined maximum length or employ dynamic allocation to allow it to hold a variable number of elements.

When a string appears literally in source code, it is known as a string literal or an anonymous string.[1]

In formal languages, which are used in mathematical logic and theoretical computer science, a string is a finite sequence of symbols that are chosen from a set called an alphabet.

Purpose

edit

A primary purpose of strings is to store human-readable text, like words and sentences. Strings are used to communicate information from a computer program to the user of the program.[2] A program may also accept string input from its user. Further, strings may store data expressed as characters yet not intended for human reading.

Example strings and their purposes:

  • A message like "file upload complete" is a string that software shows to end users. In the program's source code, this message would likely appear as a string literal.
  • User-entered text, like "I got a new job today" as a status update on a social media service. Instead of a string literal, the software would likely store this string in a database.
  • Alphabetical data, like "AGATGCCGT" representing nucleic acid sequences of DNA.[3]
  • Computer settings or parameters, like "?action=edit" as a URL query string. Often these are intended to be somewhat human-readable, though their primary purpose is to communicate to computers.

The term string may also designate a sequence of data or computer records other than characters — like a "string of bits" — but when used without qualification it refers to strings of characters.[4]

History

edit

Use of the word "string" to mean any items arranged in a line, series or succession dates back centuries.[5][6] In 19th-century typesetting, compositors used the term "string" to denote a length of type printed on paper; the string would be measured to determine the compositor's pay.[7][4][8]

Use of the word "string" to mean "a sequence of symbols or linguistic elements in a definite order" emerged from mathematics, symbolic logic, and linguistic theory to speak about the formal behavior of symbolic systems, setting aside the symbols' meaning.[4]

For example, logician C. I. Lewis wrote in 1918:[9]

A mathematical system is any set of strings of recognisable marks in which some of the strings are taken initially and the remainder derived from these by operations performed according to rules which are independent of any meaning assigned to the marks. That a system should consist of 'marks' instead of sounds or odours is immaterial.

According to Jean E. Sammet, "the first realistic string handling and pattern matching language" for computers was COMIT in the 1950s, followed by the SNOBOL language of the early 1960s.[10]

String datatypes

edit

A string datatype is a datatype modeled on the idea of a formal string. Strings are such an important and useful datatype that they are implemented in nearly every programming language. In some languages they are available as primitive types and in others as composite types. The syntax of most high-level programming languages allows for a string, usually quoted in some way, to represent an instance of a string datatype; such a meta-string is called a literal or string literal.

String length

edit

Although formal strings can have an arbitrary finite length, the length of strings in real languages is often constrained to an artificial maximum. In general, there are two types of string datatypes: fixed-length strings, which have a fixed maximum length to be determined at compile time and which use the same amount of memory whether this maximum is needed or not, and variable-length strings, whose length is not arbitrarily fixed and which can use varying amounts of memory depending on the actual requirements at run time (see Memory management). Most strings in modern programming languages are variable-length strings. Of course, even variable-length strings are limited in length by the amount of available memory. The string length can be stored as a separate integer (which may put another artificial limit on the length) or implicitly through a termination character, usually a character value with all bits zero such as in C programming language. See also "Null-terminated" below.

Character encoding

edit

String datatypes have historically allocated one byte per character, and, although the exact character set varied by region, character encodings were similar enough that programmers could often get away with ignoring this, since characters a program treated specially (such as period and space and comma) were in the same place in all the encodings a program would encounter. These character sets were typically based on ASCII or EBCDIC. If text in one encoding was displayed on a system using a different encoding, text was often mangled, though often somewhat readable and some computer users learned to read the mangled text.

Logographic languages such as Chinese, Japanese, and Korean (known collectively as CJK) need far more than 256 characters (the limit of a one 8-bit byte per-character encoding) for reasonable representation. The normal solutions involved keeping single-byte representations for ASCII and using two-byte representations for CJK ideographs. Use of these with existing code led to problems with matching and cutting of strings, the severity of which depended on how the character encoding was designed. Some encodings such as the EUC family guarantee that a byte value in the ASCII range will represent only that ASCII character, making the encoding safe for systems that use those characters as field separators. Other encodings such as ISO-2022 and Shift-JIS do not make such guarantees, making matching on byte codes unsafe. These encodings also were not "self-synchronizing", so that locating character boundaries required backing up to the start of a string, and pasting two strings together could result in corruption of the second string.

Unicode has simplified the picture somewhat. Most programming languages now have a datatype for Unicode strings. Unicode's preferred byte stream format UTF-8 is designed not to have the problems described above for older multibyte encodings. UTF-8, UTF-16 and UTF-32 require the programmer to know that the fixed-size code units are different from the "characters", the main difficulty currently is incorrectly designed APIs that attempt to hide this difference (UTF-32 does make code points fixed-sized, but these are not "characters" due to composing codes).

Implementations

edit

Some languages, such as C++, Perl and Ruby, normally allow the contents of a string to be changed after it has been created; these are termed mutable strings. In other languages, such as Java, JavaScript, Lua, Python, and Go, the value is fixed and a new string must be created if any alteration is to be made; these are termed immutable strings. Some of these languages with immutable strings also provide another type that is mutable, such as Java and .NET's StringBuilder, the thread-safe Java StringBuffer, and the Cocoa NSMutableString. There are both advantages and disadvantages to immutability: although immutable strings may require inefficiently creating many copies, they are simpler and completely thread-safe.

Strings are typically implemented as arrays of bytes, characters, or code units, in order to allow fast access to individual units or substrings—including characters when they have a fixed length. A few languages such as Haskell implement them as linked lists instead.

A lot of high-level languages provide strings as a primitive data type, such as JavaScript and PHP, while most others provide them as a composite data type, some with special language support in writing literals, for example, Java and C#.

Some languages, such as C, Prolog and Erlang, avoid implementing a dedicated string datatype at all, instead adopting the convention of representing strings as lists of character codes. Even in programming languages having a dedicated string type, string can usually be iterated as a sequence character codes, like lists of integers or other values.

Representations

edit

Representations of strings depend heavily on the choice of character repertoire and the method of character encoding. Older string implementations were designed to work with repertoire and encoding defined by ASCII, or more recent extensions like the ISO 8859 series. Modern implementations often use the extensive repertoire defined by Unicode along with a variety of complex encodings such as UTF-8 and UTF-16.

The term byte string usually indicates a general-purpose string of bytes, rather than strings of only (readable) characters, strings of bits, or such. Byte strings often imply that bytes can take any value and any data can be stored as-is, meaning that there should be no value interpreted as a termination value.

Most string implementations are very similar to variable-length arrays with the entries storing the character codes of corresponding characters. The principal difference is that, with certain encodings, a single logical character may take up more than one entry in the array. This happens for example with UTF-8, where single codes (UCS code points) can take anywhere from one to four bytes, and single characters can take an arbitrary number of codes. In these cases, the logical length of the string (number of characters) differs from the physical length of the array (number of bytes in use). UTF-32 avoids the first part of the problem.

Null-terminated

edit

The length of a string can be stored implicitly by using a special terminating character; often this is the null character (NUL), which has all bits zero, a convention used and perpetuated by the popular C programming language.[11] Hence, this representation is commonly referred to as a C string. This representation of an n-character string takes n + 1 space (1 for the terminator), and is thus an implicit data structure.

In terminated strings, the terminating code is not an allowable character in any string. Strings with length field do not have this limitation and can also store arbitrary binary data.

An example of a null-terminated string stored in a 10-byte buffer, along with its ASCII (or more modern UTF-8) representation as 8-bit hexadecimal numbers is:

F R A N K NUL k e f w
4616 5216 4116 4E16 4B16 0016 6B16 6516 6616 7716

The length of the string in the above example, "FRANK", is 5 characters, but it occupies 6 bytes. Characters after the terminator do not form part of the representation; they may be either part of other data or just garbage. (Strings of this form are sometimes called ASCIZ strings, after the original assembly language directive used to declare them.)

Byte- and bit-terminated

edit

Using a special byte other than null for terminating strings has historically appeared in both hardware and software, though sometimes with a value that was also a printing character. $ was used by many assembler systems, : used by CDC systems (this character had a value of zero), and the ZX80 used "[12] since this was the string delimiter in its BASIC language.

Somewhat similar, "data processing" machines like the IBM 1401 used a special word mark bit to delimit strings at the left, where the operation would start at the right. This bit had to be clear in all other parts of the string. This meant that, while the IBM 1401 had a seven-bit word, almost no-one ever thought to use this as a feature, and override the assignment of the seventh bit to (for example) handle ASCII codes.

Early microcomputer software relied upon the fact that ASCII codes do not use the high-order bit, and set it to indicate the end of a string. It must be reset to 0 prior to output.[13]

Length-prefixed

edit

The length of a string can also be stored explicitly, for example by prefixing the string with the length as a byte value. This convention is used in many Pascal dialects; as a consequence, some people call such a string a Pascal string or P-string. Storing the string length as byte limits the maximum string length to 255. To avoid such limitations, improved implementations of P-strings use 16-, 32-, or 64-bit words to store the string length. When the length field covers the address space, strings are limited only by the available memory.

If the length is bounded, then it can be encoded in constant space, typically a machine word, thus leading to an implicit data structure, taking n + k space, where k is the number of characters in a word (8 for 8-bit ASCII on a 64-bit machine, 1 for 32-bit UTF-32/UCS-4 on a 32-bit machine, etc.). If the length is not bounded, encoding a length n takes log(n) space (see fixed-length code), so length-prefixed strings are a succinct data structure, encoding a string of length n in log(n) + n space.

In the latter case, the length-prefix field itself does not have fixed length, therefore the actual string data needs to be moved when the string grows such that the length field needs to be increased.

Here is a Pascal string stored in a 10-byte buffer, along with its ASCII / UTF-8 representation:

length F R A N K k e f w
0516 4616 5216 4116 4E16 4B16 6B16 6516 6616 7716

Strings as records

edit

Many languages, including object-oriented ones, implement strings as records with an internal structure like:

class string {
  size_t length;
  char *text;
};

However, since the implementation is usually hidden, the string must be accessed and modified through member functions. text is a pointer to a dynamically allocated memory area, which might be expanded as needed. See also string (C++).

Other representations

edit

Both character termination and length codes limit strings: For example, C character arrays that contain null (NUL) characters cannot be handled directly by C string library functions: Strings using a length code are limited to the maximum value of the length code.

Both of these limitations can be overcome by clever programming.

It is possible to create data structures and functions that manipulate them that do not have the problems associated with character termination and can in principle overcome length code bounds. It is also possible to optimize the string represented using techniques from run length encoding (replacing repeated characters by the character value and a length) and Hamming encoding[clarification needed].

While these representations are common, others are possible. Using ropes makes certain string operations, such as insertions, deletions, and concatenations more efficient.

The core data structure in a text editor is the one that manages the string (sequence of characters) that represents the current state of the file being edited. While that state could be stored in a single long consecutive array of characters, a typical text editor instead uses an alternative representation as its sequence data structure—a gap buffer, a linked list of lines, a piece table, or a rope—which makes certain string operations, such as insertions, deletions, and undoing previous edits, more efficient.[14]

Security concerns

edit

The differing memory layout and storage requirements of strings can affect the security of the program accessing the string data. String representations requiring a terminating character are commonly susceptible to buffer overflow problems if the terminating character is not present, caused by a coding error or an attacker deliberately altering the data. String representations adopting a separate length field are also susceptible if the length can be manipulated. In such cases, program code accessing the string data requires bounds checking to ensure that it does not inadvertently access or change data outside of the string memory limits.

String data is frequently obtained from user input to a program. As such, it is the responsibility of the program to validate the string to ensure that it represents the expected format. Performing limited or no validation of user input can cause a program to be vulnerable to code injection attacks.

Literal strings

edit

Sometimes, strings need to be embedded inside a text file that is both human-readable and intended for consumption by a machine. This is needed in, for example, source code of programming languages, or in configuration files. In this case, the NUL character does not work well as a terminator since it is normally invisible (non-printable) and is difficult to input via a keyboard. Storing the string length would also be inconvenient as manual computation and tracking of the length is tedious and error-prone.

Two common representations are:

  • Surrounded by quotation marks (ASCII 0x22 double quote "str" or ASCII 0x27 single quote 'str'), used by most programming languages. To be able to include special characters such as the quotation mark itself, newline characters, or non-printable characters, escape sequences are often available, usually prefixed with the backslash character (ASCII 0x5C).
  • Terminated by a newline sequence, for example in Windows INI files.

Non-text strings

edit

While character strings are very common uses of strings, a string in computer science may refer generically to any sequence of homogeneously typed data. A bit string or byte string, for example, may be used to represent non-textual binary data retrieved from a communications medium. This data may or may not be represented by a string-specific datatype, depending on the needs of the application, the desire of the programmer, and the capabilities of the programming language being used. If the programming language's string implementation is not 8-bit clean, data corruption may ensue.

C programmers draw a sharp distinction between a "string", aka a "string of characters", which by definition is always null terminated, vs. a "array of characters" which may be stored in the same array but is often not null terminated. Using C string handling functions on such an array of characters often seems to work, but later leads to security problems.[15][16][17]

String processing algorithms

edit

There are many algorithms for processing strings, each with various trade-offs. Competing algorithms can be analyzed with respect to run time, storage requirements, and so forth. The name stringology was coined in 1984 by computer scientist Zvi Galil for the theory of algorithms and data structures used for string processing.[18][19][20]

Some categories of algorithms include:

Advanced string algorithms often employ complex mechanisms and data structures, among them suffix trees and finite-state machines.

Character string-oriented languages and utilities

edit

Character strings are such a useful datatype that several languages have been designed in order to make string processing applications easy to write. Examples include the following languages:

Many Unix utilities perform simple string manipulations and can be used to easily program some powerful string processing algorithms. Files and finite streams may be viewed as strings.

Some APIs like Multimedia Control Interface, embedded SQL or printf use strings to hold commands that will be interpreted.

Many scripting programming languages, including Perl, Python, Ruby, and Tcl employ regular expressions to facilitate text operations. Perl is particularly noted for its regular expression use,[21] and many other languages and applications implement Perl compatible regular expressions.

Some languages such as Perl and Ruby support string interpolation, which permits arbitrary expressions to be evaluated and included in string literals.

Character string functions

edit

String functions are used to create strings or change the contents of a mutable string. They also are used to query information about a string. The set of functions and their names varies depending on the computer programming language.

The most basic example of a string function is the string length function – the function that returns the length of a string (not counting any terminator characters or any of the string's internal structural information) and does not modify the string. This function is often named length or len. For example, length("hello world") would return 11. Another common function is concatenation, where a new string is created by appending two strings, often this is the + addition operator.

Some microprocessor's instruction set architectures contain direct support for string operations, such as block copy (e.g. In intel x86m REPNZ MOVSB).[22]

Formal theory

edit

Let Σ be a finite set of distinct, unambiguous symbols (alternatively called characters), called the alphabet. A string (or word[23] or expression[24]) over Σ is any finite sequence of symbols from Σ.[25] For example, if Σ = {0, 1}, then 01011 is a string over Σ.

The length of a string s is the number of symbols in s (the length of the sequence) and can be any non-negative integer; it is often denoted as |s|. The empty string is the unique string over Σ of length 0, and is denoted ε or λ.[25][26]

The set of all strings over Σ of length n is denoted Σn. For example, if Σ = {0, 1}, then Σ2 = {00, 01, 10, 11}. We have Σ0 = {ε} for every alphabet Σ.

The set of all strings over Σ of any length is the Kleene closure of Σ and is denoted Σ*. In terms of Σn,

 

For example, if Σ = {0, 1}, then Σ* = {ε, 0, 1, 00, 01, 10, 11, 000, 001, 010, 011, ...}. Although the set Σ* itself is countably infinite, each element of Σ* is a string of finite length.

A set of strings over Σ (i.e. any subset of Σ*) is called a formal language over Σ. For example, if Σ = {0, 1}, the set of strings with an even number of zeros, {ε, 1, 00, 11, 001, 010, 100, 111, 0000, 0011, 0101, 0110, 1001, 1010, 1100, 1111, ...}, is a formal language over Σ.

Concatenation and substrings

edit

Concatenation is an important binary operation on Σ*. For any two strings s and t in Σ*, their concatenation is defined as the sequence of symbols in s followed by the sequence of characters in t, and is denoted st. For example, if Σ = {a, b, ..., z}, s = bear, and t = hug, then st = bearhug and ts = hugbear.

String concatenation is an associative, but non-commutative operation. The empty string ε serves as the identity element; for any string s, εs = sε = s. Therefore, the set Σ* and the concatenation operation form a monoid, the free monoid generated by Σ. In addition, the length function defines a monoid homomorphism from Σ* to the non-negative integers (that is, a function  , such that  ).

A string s is said to be a substring or factor of t if there exist (possibly empty) strings u and v such that t = usv. The relation "is a substring of" defines a partial order on Σ*, the least element of which is the empty string.

Prefixes and suffixes

edit

A string s is said to be a prefix of t if there exists a string u such that t = su. If u is nonempty, s is said to be a proper prefix of t. Symmetrically, a string s is said to be a suffix of t if there exists a string u such that t = us. If u is nonempty, s is said to be a proper suffix of t. Suffixes and prefixes are substrings of t. Both the relations "is a prefix of" and "is a suffix of" are prefix orders.

Reversal

edit

The reverse of a string is a string with the same symbols but in reverse order. For example, if s = abc (where a, b, and c are symbols of the alphabet), then the reverse of s is cba. A string that is the reverse of itself (e.g., s = madam) is called a palindrome, which also includes the empty string and all strings of length 1.

Rotations

edit

A string s = uv is said to be a rotation of t if t = vu. For example, if Σ = {0, 1} the string 0011001 is a rotation of 0100110, where u = 00110 and v = 01. As another example, the string abc has three different rotations, viz. abc itself (with u=abc, v=ε), bca (with u=bc, v=a), and cab (with u=c, v=ab).

Lexicographical ordering

edit

It is often useful to define an ordering on a set of strings. If the alphabet Σ has a total order (cf. alphabetical order) one can define a total order on Σ* called lexicographical order. The lexicographical order is total if the alphabetical order is, but is not well-founded for any nontrivial alphabet, even if the alphabetical order is. For example, if Σ = {0, 1} and 0 < 1, then the lexicographical order on Σ* includes the relationships ε < 0 < 00 < 000 < ... < 0001 < ... < 001 < ... < 01 < 010 < ... < 011 < 0110 < ... < 01111 < ... < 1 < 10 < 100 < ... < 101 < ... < 111 < ... < 1111 < ... < 11111 ... With respect to this ordering, e.g. the infinite set { 1, 01, 001, 0001, 00001, 000001, ... } has no minimal element.

See Shortlex for an alternative string ordering that preserves well-foundedness. For the example alphabet, the shortlex order is ε < 0 < 1 < 00 < 01 < 10 < 11 < 000 < 001 < 010 < 011 < 100 < 101 < 0110 < 111 < 0000 < 0001 < 0010 < 0011 < ... < 1111 < 00000 < 00001 ...

String operations

edit

A number of additional operations on strings commonly occur in the formal theory. These are given in the article on string operations.

Topology

edit
 
(Hyper)cube of binary strings of length 3

Strings admit the following interpretation as nodes on a graph, where k is the number of symbols in Σ:

  • Fixed-length strings of length n can be viewed as the integer locations in an n-dimensional hypercube with sides of length k-1.
  • Variable-length strings (of finite length) can be viewed as nodes on a perfect k-ary tree.
  • Infinite strings (otherwise not considered here) can be viewed as infinite paths on a k-node complete graph.

The natural topology on the set of fixed-length strings or variable-length strings is the discrete topology, but the natural topology on the set of infinite strings is the limit topology, viewing the set of infinite strings as the inverse limit of the sets of finite strings. This is the construction used for the p-adic numbers and some constructions of the Cantor set, and yields the same topology.

Isomorphisms between string representations of topologies can be found by normalizing according to the lexicographically minimal string rotation.

See also

edit

References

edit
  1. ^ "Introduction To Java – MFC 158 G". Archived from the original on 2025-08-06. String literals (or constants) are called 'anonymous strings'
  2. ^ de St. Germain, H. James. "Strings". University of Utah, Kahlert School of Computing.
  3. ^ Francis, David M.; Merk, Heather L. (November 14, 2019). "DNA as a Biochemical Entity and Data String".
  4. ^ a b c Burchfield, R.W. (1986). "string". A Supplement to the Oxford English Dictionary. Oxford at the Clarendon Press.
  5. ^ "string". The Oxford English Dictionary. Vol. X. Oxford at the Clarendon Press. 1933.
  6. ^ "string (n.)". Online Etymology Dictionary.
  7. ^ Whitney, William Dwight; Smith, Benjamin E. "string". The Century Dictionary. New York: The Century Company. p. 5994.
  8. ^ "Old Union's Demise". Milwaukee Sentinel. January 11, 1898. p. 3.
  9. ^ Lewis, C.I. (1918). A survey of symbolic logic. Berkeley: University of California Press. p. 355.
  10. ^ Sammet, Jean E. (July 1972). "Programming Languages: History and Future" (PDF). Communications of the ACM. 15 (7). doi:10.1145/361454.361485. S2CID 2003242.
  11. ^ Bryant, Randal E.; David, O'Hallaron (2003), Computer Systems: A Programmer's Perspective (2003 ed.), Upper Saddle River, NJ: Pearson Education, p. 40, ISBN 0-13-034074-X, archived from the original on 2025-08-06
  12. ^ Wearmouth, Geoff. "An Assembly Listing of the ROM of the Sinclair ZX80". Archived from the original on August 15, 2015.
  13. ^ Allison, Dennis. "Design Notes for Tiny BASIC". Archived from the original on 2025-08-06.
  14. ^ Charles Crowley. "Data Structures for Text Sequences" Archived 2025-08-06 at the Wayback Machine. Section "Introduction" Archived 2025-08-06 at the Wayback Machine.
  15. ^ "strlcpy and strlcat - consistent, safe, string copy and concatenation." Archived 2025-08-06 at the Wayback Machine
  16. ^ "A rant about strcpy, strncpy and strlcpy." Archived 2025-08-06 at the Wayback Machine
  17. ^ Keith Thompson. "No, strncpy() is not a "safer" strcpy()". 2012.
  18. ^ "The Prague Stringology Club". stringology.org. Archived from the original on 1 June 2015. Retrieved 23 May 2015.
  19. ^ Evarts, Holly (18 March 2021). "Former Dean Zvi Galil Named a Top 10 Most Influential Computer Scientist in the Past Decade". Columbia Engineering. He invented the terms 'stringology,' which is a subfield of string algorithms,
  20. ^ Crochemore, Maxime (2002). Jewels of stringology. Singapore. p. v. ISBN 981-02-4782-6. The term stringology is a popular nickname for string algorithms as well as for text algorithms.{{cite book}}: CS1 maint: location missing publisher (link)
  21. ^ "Essential Perl". Archived from the original on 2025-08-06. Perl's most famous strength is in string manipulation with regular expressions.
  22. ^ "x86 string instructions". Archived from the original on 2025-08-06.
  23. ^ Fletcher, Peter; Hoyle, Hughes; Patty, C. Wayne (1991). Foundations of Discrete Mathematics. PWS-Kent. p. 114. ISBN 0-53492-373-9. Let Σ be an alphabet. A nonempty word over Σ is a finite sequence with domain In (for some n ∈ ?) and codomain Σ.
  24. ^ Shoenfield, Joseph R. (2010) [1967]. Mathematical Logic (Reprint ed.). CRC Press. p. 2. ISBN 978-156881135-2. Any finite sequence of symbols of a language is called an expression of that language.
  25. ^ a b Barbara H. Partee; Alice ter Meulen; Robert E. Wall (1990). Mathematical Methods in Linguistics. Kluwer.
  26. ^ John E. Hopcroft, Jeffrey D. Ullman (1979). Introduction to Automata Theory, Languages, and Computation. Addison-Wesley. ISBN 0-201-02988-X. Here: sect.1.1, p.1
什么是有源音箱 什么食物含蛋白质多 皮下出血点是什么原因 鲁迅真名叫什么 送女朋友什么礼物好
中医治未病是什么意思 花椒吃多了对身体有什么影响 哺乳期可以吃什么消炎药 化肥对人体有什么危害 梦到捡到钱是什么预兆
头一直摇晃是什么病 酉鬼念什么 子宫形态失常是什么意思 直径是什么意思 峦读什么
多发纳氏囊肿是什么意思 白头翁是什么动物 精斑是什么 激光脱毛对人体有没有什么危害 713是什么星座
喜欢的反义词是什么hcv7jop4ns6r.cn 百无一用是什么意思sscsqa.com 维生素b2起什么作用hcv8jop2ns7r.cn belkin是什么牌子hcv9jop1ns6r.cn 不但而且是什么关系luyiluode.com
90岁属什么生肖hcv8jop5ns3r.cn 疏导是什么意思hcv8jop9ns9r.cn 产后恶露吃什么排干净wuhaiwuya.com 张若昀原名叫什么hcv9jop2ns3r.cn 今年78岁属什么生肖bjhyzcsm.com
老人肚子胀是什么原因yanzhenzixun.com 狮子座是什么象星座hcv9jop8ns1r.cn 半夜猫叫有什么预兆hcv8jop6ns6r.cn 小儿疳积是什么症状hcv9jop4ns2r.cn 优生四项是检查什么hcv8jop6ns0r.cn
头发有点黄是什么原因hcv8jop3ns3r.cn 低血压高是什么原因hcv9jop1ns3r.cn 谭咏麟属什么生肖hcv8jop8ns5r.cn 区武装部部长是什么级别hcv9jop0ns4r.cn 玄胡又叫什么hcv8jop3ns5r.cn
百度