Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Armin1983

macrumors newbie
Original poster
Jan 29, 2012
11
0
Hello guys,

Imagine, I have a NSString object, inside it, there are strings, i want to know how size it is on disk if i save the content of file on computer as a file.
 
NSFileManager can be used to find out the size of a file, specifically: attributesOfItemAtPath which returns a dictionary that has fileSize information.
 
NSFileManager can be used to find out the size of a file, specifically: attributesOfItemAtPath which returns a dictionary that has fileSize information.

As i said, i want to know the size of the future file before i save the content of NSString to a file on my disk.
 
This page from CocoaDev answers the question thoroughly:

http://www.cocoadev.com/index.pl?FileSize

Short answer: you can use NSString's –lengthOfBytesUsingEncoding: to get the number of bytes, but the actual size of that file on disk will dependant on other factors. As others have said, it will be useful to know why you need this information so we can suggest a suitable solution.
 
This page from CocoaDev answers the question thoroughly:

http://www.cocoadev.com/index.pl?FileSize

Short answer: you can use NSString's –lengthOfBytesUsingEncoding: to get the number of bytes, but the actual size of that file on disk will dependant on other factors. As others have said, it will be useful to know why you need this information so we can suggest a suitable solution.

Thanks for guidance,

my nsstring object is loaded by html contents. how would be the solution in this case?
 
Thanks for guidance,

my nsstring object is loaded by html contents. how would be the solution in this case?

What makes you think there is a difference? Asked before, but what is it actually that you try to achieve? Usually, after people have tried for ages answering your questions, it then turns out that you asked the completely wrong questions in the first place.
 
What makes you think there is a difference? Asked before, but what is it actually that you try to achieve? Usually, after people have tried for ages answering your questions, it then turns out that you asked the completely wrong questions in the first place.

The XY Problem
.. You want to do X, and you think Y is the best way of doing it.
.. Instead of asking about X, you ask about Y.
 
The XY Problem
.. You want to do X, and you think Y is the best way of doing it.
.. Instead of asking about X, you ask about Y.

The best thing about this forum is that people don't just simply answer the question, but offer advice on the method & approach taken.

The worst thing about this forum, is that people don't just simply answer the question, but offer advice on the method & approach taken.

;)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.