ShoneSharp Language (S #) design and use introduction series (6)-String,

Source: Internet
Author: User

ShoneSharp Language (S #) design and use introduction series (6)-String,
ShoneSharp Language (S #) design and use introduction series (6)-String Author: Shone

Disclaimer: you are welcome to repost the original article, but please indicate the source, https://www.cnblogs.com/shonesharp.

Abstract: String (corresponding to String of C #), the most all-powerful type of S # language, can be used to represent text content, such as "S # formula is very distinctive. There are three string input formats for S #: "xxxxx", @ "xxxxx", and 'xxxxx '. In the S # language design, the character string has a high position. The system regards it as one of the all-around expressions of "program is data, data is program.

Software: S # language editor, runtime environment. NET 4.0, green software, single EXE run directly, no side effects. Online drive download link for https://pan.baidu.com/s/1dF4e08p

 

The Double type is introduced in the previous section. listing all the members of this type is very cool, but there is no way. The three most basic types (Double, String, Bool) must be fully listed, because they are the raw material of S. The focus will be omitted when other types are introduced later.

One or three input formats

Today, we will explain in detail the most all-powerful type of the S # language-string (corresponding to the double type of C #), which can be used to represent text content, such as "S # formula is very distinctive. Like C #, a string is memory data that cannot be modified. Only new strings can be generated for computation.

S # has three string input formats:

(1)Start with double quotation marks and end with double quotation marks. Escape Character with "\" is supported in the middle. (Same as C)

"xxxxx"

 (2)Start with double quotation marks, end with double quotation marks, and two "escape as a single" characters in the middle ". (Same as C)

@"xxxxx"

 (3)Start with single quotation marks and end with single quotation marks. The two "escape as a single" are the simplest input formats recommended by the language. (Same as JavaScript)

'xxxxx'

S # language does not have the character Byte type in C #. It can be replaced by a single character string.

Ii. all-powerful string

In the S # language design, the position of the string is very high, and the system regards it as"Programs are data and data are programs..

For example, '20' indirectly expresses the value, '(20 + 30)/2' indirectly expresses the value calculation, which can be considered as data.

Before a string ?, You can evaluate the string ,? The calculation result of '(20 + 30)/2' is 25. Is it a program now ?!

Let's look at another example with a variable:

{ 

  a = 20  , 

  b = 30  ,   

  c = "(a+b)/2"  ,   

  d = ?c

}

The calculation result is {a = 20, B = 30, c = '(a + B)/2', d = 25 }.

If you think of a string as a long and long data tape? The symbol is regarded as a program reading and writing header. Is it a prototype of the "Turing Machine" when it is executed infinitely !!!

In short, use strings in S # To improve data and program expression capabilities.

Iii. String Functions

Bool exists (String file)

Returns the string of the specified object content.

Input: exists ('d: \ hjx.txt ')

Evaluate: False

 

String format (String s, Object arg ,...)

Description: returns a formatted string with the same format as. NET.

Input: format ('Hello {0 }:{ 1} ', 10, 'hjx ')

Evaluate: 'Hello 10: hjx'

 

String read (String file)

Returns the string of the specified object content.

Input: read ('d: \ hjx.txt ')

 

Iv. string attributes

Double String. CharLen

Note: The character length value (where the Chinese character is 1 and the English word is 0.5. Ignore line breaks)

Input: x. CharLen

 

Double [] String. Chars

Description: character value Array

Input: x. Chars

 

String [] String. CommarWords

Returns a comma-separated string array of text.

Input: x. CommarWords

 

Double String. Count

Description: Character Count value.

Input: x. Count

 

Double String. EndChar

Description: end character value.

Input: x. EndChar

 

String. Identifier

Note: canonical name identifier

Input: x. Identifier

 

Bool String. IsIdentifier

Indicates whether the name is a canonical name identifier.

Input: x. IsIdentifier

 

String [] String. Lines

Returns the row string array of text.

Input: x. Lines

 

String. Lower

Description: lowercase string

Input: x. Lower

 

String. PrefixLower

Description: lowercase letters

Input: x. PrefixLower

 

String. PrefixUpper

Description: uppercase letters

Input: x. PrefixUpper

 

String. Reverse

Description: reverse the string.

Input: x. Reverse

 

String [] String. SemicolonWords

Returns the semicolon separator string array of the text.

Input: x. SemicolonWords

 

String [] String. SpaceWords

Returns a space-separated string array of text.

Input: x. SpaceWords

 

Double String. StartChar

Description: Start character value.

Input: x. StartChar

 

String. Trim

Note: Empty strings are removed from the beginning and end of the string.

Input: x. Trim

 

String. TrimEnd

Description: Empty strings are removed at the end.

Input: x. TrimEnd

 

String [] String. TrimLines

Returns the row string array of text.

Input: x. TrimLines

 

String. TrimStart

Note: Empty strings are removed from the header.

Input: x. TrimStart

 

String. Upper

Description: an uppercase string.

Input: x. Upper

 

String [] String. Words

Returns the text string array separated by a carriage return or space.

Input: x. Words

 

V. String Method

Bool String. Contains (String value)

Determines whether a specified string is included.

Input: x. Contains ('hjx ')

 

String. Del (Double I)

Returns the string to be deleted. All characters are deleted from position I.

Input: x. Del (5)

 

String. Del (Double I, Double d)

Returns the deletion string, which is d characters from position I.

Input: x. Del (5, 2)

 

Bool String. Ends (String value)

Determines whether to end with a specified string.

Input: x. Ends ('hjx ')

 

String [] String. Grow (Double n)

Description: String auto-incrementing sequence Array

Input: x. Grow (5)

 

String. Identifier (String prefix)

Note: standard name identifiers with prefixes

Input: x. Identifier ('My ')

 

Double String. IndexOf (String sub)

Returns the first index of the matched sub-string.

Input: x. IndexOf ('hjx ')

 

Double String. IndexOf (String sub, Double I)

Description: returns the first index of the matched sub-string, starting from position I.

Input: x. IndexOf ('hjx', 0)

 

Double String. IndexOf (String sub, Double I, Double d)

Description: returns the first index matching the sub-string, starting from position I and checking for d characters.

Input: x. IndexOf ('hjx)

 

Double String. IndexOfAny (String sub)

Returns the first index that matches any character in the sub.

Input: x. IndexOfAny ('hjx ')

 

Double String. IndexOfAny (String sub, Double I)

Description: returns the first index that matches any character in the sub. The index starts from position I.

Input: x. IndexOfAny ('hjx', 0)

 

Double String. IndexOfAny (String sub, Double I, Double d)

Returns the first index that matches any character in the sub, starting from position I and checking for d characters.

Input: x. IndexOfAny ('hjx)

 

String. Insert (Double I, String sub)

Returns the inserted string, and inserts the substring sub at position I.

Input: x. Insert (5, 'hjx ')

 

Double String. LastIndexOf (String sub)

Description: returns the first index of the matched sub-string.

Input: x. LastIndexOf ('hjx ')

 

Double String. LastIndexOf (String sub, Double I)

Description: returns the first index of the sub-string that matches the substring in reverse order, and checks the index from position I.

Input: x. LastIndexOf ('hjx', 5)

 

Double String. LastIndexOf (String sub, Double I, Double d)

Returns the first index of the sub-string in reverse matching mode, starting from position I and checking for d characters.

Input: x. LastIndexOf ('hjx', 5, 5)

 

Double String. LastIndexOfAny (String sub)

Returns the first index of any character in the reverse matching sub.

Input: x. LastIndexOfAny ('hjx ')

 

Double String. LastIndexOfAny (String sub, Double I)

Returns the first index of any character in the reverse matching sub, starting from position I.

Input: x. LastIndexOfAny ('hjx', 5)

 

Double String. LastIndexOfAny (String sub, Double I, Double d)

Returns the first index of any character in the reverse matching sub, starting from position I and checking for d characters.

Input: x. LastIndexOfAny ('hjx', 5, 5)

 

String. Pad (Double d)

Returns the string after the padding space alignment, and the right/left alignment corresponding to positive/negative d.

Input: x. Pad (20)

 

String. Pad (Double d, Double ch)

Returns the string after the padding character alignment, and the right/left alignment corresponding to positive/negative d.

Input: x. Pad (20, 42)

 

String. Remove (String sub)

Returns the string after the specified string is deleted.

Input: x. Remove ('hjx ')

 

String. Replace (String old, String rep)

Description: returns the string after replacing the specified string.

Input: x. Replace ('hjx', 'hjx ')

 

String [] String. Split (String g)

Returns an array of strings separated by any character in g.

Input: x. Split (',')

 

Bool String. Starts (String value)

Determines whether to start with a specified string.

Input: x. Starts ('hjx ')

 

String. Sub (Double I)

Description: returns the extracted string. All characters are extracted from position I.

Input: x. Sub (5)

 

String. Sub (Double I, Double d)

Returns the extracted string, which is d characters from position I.

Input: x. Sub (5, 2)

In fact, some operators, functions, attributes, and methods that are applicable to numeric types are not listed in this section but are described in the base type-any object (corresponding to the object of C, it not only supports strings, but also supports the calculation of arrays, lists, and data tables containing strings.

Disclaimer: you are welcome to repost the original article, but please indicate the source, https://www.cnblogs.com/shonesharp.

Software: S # language editor, runtime environment. NET 4.0, green software, single EXE run directly, no side effects. Online drive download link for https://pan.baidu.com/s/1dF4e08p


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.

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.