Definition and function of the string of data structure Foundation

Source: Internet
Author: User
Tags definition empty

The definition of a string

A string (or string) that is a finite sequence of 0 or more characters. Generally recorded as:

S= ' a1a2...an ' (n>=0)

where S is the name of the string, the sequence of characters enclosed in single quotes is the value of the string, and the number of characters in the string n is called the length of the string. A string of 0 characters is called an empty string, and its length is zero.

A substring of any contiguous character in a string is called a substring of that string. The string containing the substring is referred to as the main string accordingly. The position of a character in a sequence, usually called the character in a string. The position of the substring in the main string is represented by the position of the first character of the substring in the main string.

Example: A= ' BEI ', b= ' JING ', c= ' BEIJING ', d= ' BEI JING '

The string length is 3,4,7,8, and the a,b is a c,d substring.

The two strings are called equal if and only if the values of the two strings are equal.

  Second, the definition of the abstract data type of the string:

ADT string{

Data Objects: D={ai|ai (-characterset,i=1,2,..., n,n>=0}

Data relationship: R1={|ai-1,ai (-d,i=2,..., N}

Basic operations:

Strassign (&t,chars)

Chars is the constants quantity of words. Generates a string t whose value is equal to chars.

Strcopy (&t,s)

string s existence is copied by string s t

Strempty (S)

String s exists if s is empty string, return true otherwise return false

Strcompare (s,t)

string s and T exist, if s>t, the return value is greater than 0, if s=t, then the return value = 0, if s

Strlength (S)

The number of elements in a string s that returns s is called the length of the string.

Clearstring (&s)

String s exists to clear s to empty string

Concat (&T,S1,S2)

String S1 and S2 exist with T return a new string joined by S1 and S2

SubString (&sub,s,pos,len)

string s exist, 1<=pos<=strlength (s) and 0<=len<=strlength (s)-pos+1

Index (S,t,pos)

string s and T exist, T is Non-null, 1<=pos<=strlength (s), if there is a substring in the main string s that is the same as the string T value, it returns the position of the first occurrence after the POS character in the main string s, otherwise the function value is 0

Replace (&S,T,V)

The string s,t and V exist, T is a non-empty string, and with V replaces all occurrences of the not overlapping substrings in the main string s that are equal to T

Strinsert (&s,pos,t)

The string s and T exist, 1<=pos<=strlength (s) +1, before the first POS characters of the string s are inserted into the string t

Strdelete (&s,pos,len)

String S exists, 1<=pos<=strlength (s)-len+1 deletes the first POS characters from the string to the substring of Len

Destroystring (&s)

string s exist, then the string s are destroyed

}adt String

  Three, series operation application Example:

1 commonly used in word processing: string lookup (comparison, positioning) and replacement

Available ^QF Quick Find variable in TC integrated environment can search and replace bulk change text in Word

2-string truncation and connection

Word processing can be done using substring and string connections

 Iv. Summary

Find a few examples of string operations that you've done yourself.

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.