Definition and function of a Data Structure string

Source: Internet
Author: User

Definition and function of a Data Structure string

I. String Definition

A string (or string) is a finite sequence composed of zero or multiple characters. It is generally recorded:

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

S is the name of a string, and the Character Sequence enclosed by single quotes is the value of a string. n is the length of a string. A string with zero characters is called an empty string and its length is zero.

A sub-sequence composed of any consecutive characters in a string is called a sub-string of the string. The string containing the substring is called as the primary string. It is usually called the position of a character in a sequence in a string. The position of a substring in the primary string is expressed by the position of the first character in the primary string.

Example: a = 'bei', B = 'jing', c = 'beijing', d = 'bei jing'

The string lengths are 3, 4, 7, and 8 respectively, and a and B are all substrings of c and d.

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

  Ii. Definition of abstract data types of strings:

ADT String {

Data Object: 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 a character constant. Generate a string T whose value is equal to chars.

StrCopy (& T, S)

If the string S exists, the string T is copied from the string S.

StrEmpty (S)

If the string S exists, if S is an empty string, true is returned; otherwise false is returned.

StrCompare (S, T)

String S and T exist. If S> T, the return value is greater than 0. If S = T, the return value is 0. If S = T

StrLength (S)

The number of elements returned by the existence of string S is called the length of the string.

ClearString (& S)

The string S is removed as an empty string.

Concat (& T, S1, S2)

The S1 and S2 strings use T to return new strings connected by S1 and S2.

SubString (& Sub, S, pos, len)

String S exists. 1 <= pos <= StrLength (S) and 0 <= len <= StrLength (S)-pos + 1

Index (S, T, pos)

String S and T exist, T is not empty, 1 <= pos <= StrLength (S), if the main string S contains a substring with the same value as the string T, returns the position where it first appears after the pos character in the main string S. Otherwise, the function value is 0.

Replace (& S, T, V)

String S, T, and V exist. T is a non-empty string. Use V to replace all non-overlapping substrings that are equal to T in the main string S.

StrInsert (& S, pos, T)

String S and T exist, 1 <= pos <= StrLength (S) + 1, insert string T before the pos character of string S

StrDelete (& S, pos, len)

String S exists. 1 <= pos <= StrLength (S)-len + 1 deletes the substring whose length is len from the string

DestroyString (& S)

If the string S exists, the string S is destroyed.

} ADT String

  3. Example of a string operation:

1 commonly used in Text Processing: string search (comparison, positioning) and replacement

In the TC integration environment, ^ QF can be used to quickly search for and replace variables in WORD to change text in batches.

2 string truncation and Connection

You can use substrings and string connections for text processing.

 Iv. Summary

Find several examples of string operations that you have 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.