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