Swift3.0 language Tutorial Get string encoding and hash address

Source: Internet
Author: User

Swift3.0 language Tutorial Get string encoding and hash address

Swift3.0 Language Tutorial Get the string encoding and hash address, the following will explain how to get the other content in the string.

1. Get string encoding

In NSString, you can use 2 properties to get the string encoding, respectively, the Availablestringencodings property and the Defaultcstringencoding property.

(1) The Availablestringencodings property can be used to obtain nsstring available string encoding. Its grammatical form is as follows:

Class var availablestringencodings:unsafepointer<uint> {get}

Example 1-26 below gets the string encoding that is available for nsstring.

Import Foundation

Print (nsstring.availablestringencodings)

The results of the operation are as follows:

0x0000000100a05480

(2) The Defaultcstringencoding property can be used to obtain the NSString default C string encoding, which has the following syntax:

Class var defaultcstringencoding:uint {get}

Example 1-27 below gets the nsstring default C string encoding.

Import Foundation

Print (nsstring.defaultcstringencoding)

The results of the operation are as follows:

2147483673

2. Get the string hash address

The hash attribute can be used to get the hashed address of a string, with the following syntax:

var hash:int {Get}

"Example 1-28" gets the hash address of the string

Import Foundation

var a=nsstring (string: "Hello")

print (A.hash)// gets the hash address of the string

The results of the operation are as follows:

13284511477017

Related reading: Swift3.0 language tutorial using Unicode normalization to get strings

Swift3.0 language Tutorial Get string encoding and hash address

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.