Swift string concatenation, interception

Source: Internet
Author: User
Import UIKit

//swift string
in string//1>swift is a struct with higher performance
//2>nsstring is an OC object with slightly worse performance
//3> String supports direct traversal
of//4>swift provides a seamless conversion of string and nsstring let
str = "Hello World"

//Traversal string for
C in str.characters{
    Print (c)
}

//string concatenation
//concatenation between two strings let
str1 = "Hello" let

str2 = "World"

Let STR3 = str1 + str2

//concatenation of strings and other identifiers let
name = ' ZYF ' let-age

= '

height = 1.88 let

info = ' my Name is \ (name), my time is \ (age), my height is \ (height) "

//concatenation string, string formatting let
minent = 2 let

seconds = 8 let

timestring = String (format: "%02d:%02d", Arguments:[minent,seconds])

print (timestring)

// Intercept of the string let
urlstr = "www.zhengyanfeng.com"

//Convert the string type to NSString type let


header = (urlstr as NSString). SUBSTRING (to:3) let

BODY = (urlstr as NSString). Substring (With:nsrange (Location:4, length:12)) let

Afterbod y = (urlstr as NSString). SUBSTRING (from:17)


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.