Swif creating string and string comparisons

Source: Internet
Author: User

Strings are concatenated with multiple strings.


There are 2 types of swift strings: string and NSString


The type of string is just string, in fact string is a struct


You can assign values directly, or you can create them through the constructor of the struct


Let Emptystring=string ()



By using let and VAR declaration variables for strings to implement immutable strings and mutable strings, the Let-declared string is immutable, VAR is variable



Comparison of strings:


1, size comparison;>,<


2. Equal comparison


Unlike comparison sizes, String and character types use = = and = comparisons, but cannot use the = = and!== operators

NSString can use = = = and!==


3, prefix and suffix comparison


(1) The string Hassuffix () method to determine the suffix;


Doc.hassuffix (". docx");


Doc is a string type



(2) Hasprefix of Strings ("Java")


Lowercasedoc.hasprefix ("Java")

Lowercasedoc is a String type






This article is from the "Ordinary Road" blog, please be sure to keep this source http://linjohn.blog.51cto.com/1026193/1619428

Swif creating string and string comparisons

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.