iOS to determine if the content in the TextView is empty and remove the null character method and Swift's for loop

Source: Internet
Author: User
iOS to determine whether the content in the TextView is empty in the development of iOS, it is often necessary to determine whether the data in the TextView box is empty or whether it is a space, following the syntax of Swift as an example to explain a method of judgment
//method one
if self.titleValue.text? .StringByTrimmingCharactersInSet (NScharacterSet.WhiteSpaceCharac-
terSet ()). StringLength () == 0 {
     print ("What is used here is to remove all space characters in the textView, and then determine whether the length of the characters after removing the space characters is 0")
}

//Method Two
if self.titleValue.text? .StringByTrimmingCharactersInSet (NScharacterSet.WhiteSpaceCharac-
terSet ()) == "" {
     print ("Use here to directly determine whether the characters in the textView string after removing the space characters are null characters")
}  
Ways to get rid of String hollow characters
var string = "Hello Hello world"
string = String.stringbyreplacingoccurrencesofstring ("", Withstring: "")//This When the string
changes to "Hellohelloworldworld"    
Swift's for Loop
For I in string.characters{
    if I >= "0" && I <= "9" {
        //delete a numeric character in a string let
        index = String.ran Geofstring ("\ (i)")
        String.removerange (index!)
    }
} 
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.