The difference between stringbyappendingpathcomponent and stringbyappendingstring

Source: Internet
Author: User

The difference between stringbyappendingpathcomponent and stringbyappendingstring 

stringByAppendingPathComponent

    1. NSString * FilePath3 = [Documentspath stringbyappendingpathcomponent:@ "Dictionary"];

Stringbyappendingstring


    1. NSString * FilePath = [Documentspath stringbyappendingstring:@ "/hello.txt"];

Comparison of the two

1, the latter need to add "/", the former does not need to add

2, the former path print out:/users/mymacbook/library/developer/coresimulator/devices/c1b4afe9-2058-40a6-b868-101e166ff961/data/ Containers/data/application/79cb8a9f-1000-4360-a9ea-801adf1e0044/documents/database.sqlite
The latter path is printed out:/users/mymacbook/library/developer/coresimulator/devices/c1b4afe9-2058-40a6-b868-101e166ff961/data/ Containers/data/application/79cb8a9f-1000-4360-a9ea-801adf1e0044/documents

stringByAppendingPathComponent

is to link the previous path format with the normal string format that follows, and return in the path format.

For example: Get the Program home directory NSString *path =nshomedirectory (); The obtained path is "/root/user/";

Path = [path stringbyappendingpathcomponent:@ "Abc.txt"], and the latter path is "/root/user/abc.txt".




The difference between stringbyappendingpathcomponent and stringbyappendingstring

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.