SWIFT3.0 Common operations include delete string (string), replace string, insert string

Source: Internet
Author: User

1. Delete the string at the specified location,

Let str = "ABCDEFG"

Let STR3 = str.substring (From:str.index (Str.endindex, Offsetby:-4))

Print (STR3) output DEFG

Let STR4 = str.substring (To:str.index (Str.startindex, Offsetby:4))

Print (STR4) output ABCD


2. Inserting a string

var str = "ABCDEFG"

Str.insert (contentsof: "* * * *". Characters, At:str.index (Str.startindex, Offsetby:3))

Print (str) output ABC****DEFG

3. Replacing strings

var str = "ABCDEFG"

Let str2 = Str.replacingoccurrences (of: "AB", With: "")

Print (str2) output CDEFG


This article is from the "common Methods of swift3" blog, so be sure to keep this source http://13210199.blog.51cto.com/13200199/1955754

SWIFT3.0 Common operations include delete string (string), replace string, insert string

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.