Re: Omission of % character when loading a string from a file?
Re: Omission of % character when loading a string from a file?
- Subject: Re: Omission of % character when loading a string from a file?
- From: David Remahl <email@hidden>
- Date: Thu, 26 Dec 2002 20:53:28 +0100
No, it does _not_.
-[NSString initWithContentsOfFile] does the following, according to the
documentation:
Initializes the receiver, a newly allocated NSString, by reading
characters from the file named by path. If the contents begin with a
byte-order mark (U+FEFF or U+FFFE), interprets the contents as Unicode
characters; otherwise interprets the contents as characters in the
default C string encoding. Returns self, or nil if the file can't be
opened.
-[NSDictionary initWithContentsOfFile] och -[NSArray
initWithContentsOfFile] on the other hand, assume the file is in the
XML property list format.
I cannot reproduce the problem you have (-> the original poster). I
think your problem is that you do:
NSLog(string) and not NSLog(@"%@", string), as others have pointed out.
/ Regards, David Remahl
On Thursday, December 26, 2002, at 08:36 PM, Hasan Diwan wrote:
initWithContentsOfFile assumes the file is in XML, where the '%' sign
is an "entity declaration"
(http://archive.devx.com/projectcool/developer/xmlz/xmldtd/
dtdentities.html).
On Thursday, December 26, 2002, at 01:10 PM, Jan Van Boghout wrote:
Nope, NSLog isn't fooling me. I'm parsing css files, and my % signs
are
lost. I am trying this out with the css file I downloaded at:
http://www.w3c.org/Style/shadows.css
In one property there is a font size of 140%, but it comes through as
140. And the % isn't lost in my parsing, it's not in the string that
is
loaded in the first place either. I select a file using an open panel
and take its path. Then I do this:
css = [[NSMutableString alloc] initWithContentsOfFile:[op filename]];
No % signs are in the resulting string. This is the only line of code
that causes it, so I guess loading a string directly from a file isn't
what I should be doing. But what should I do then? I'd think this is
supposed to work.
JVB
The second poster might be more on target. How are you verifying the
read contents? Try the suggestion of:
NSLog("%s", string);
If you already were doing that and you are still missing %s, and it
opens in TextEdit as plain text, then try opening it in PB to verify
it is plain text.
Beyond those I would need to try playing with code or the file in
question.
Michael
On Thursday, December 26, 2002, at 09:38 AM, Jan Van Boghout wrote:
Hmm. So encoding is the problem. It's a css file from the official
W3C site, but the problem stays when making a plain text file from
TextEdit. How could I get the correct file encoding and load it
with
that encoding?
Is the file Unicode? Does it have the unicode encoding bytes at
the
front of the file? How was the file created?
Michael Latta
On Thursday, December 26, 2002, at 09:13 AM, Jan Van Boghout
wrote:
Why is it that when I load a plain text file as a string, every %
character seems to disappear completely?
I use : [[NSMutableString alloc] initWithContentsOfFile:path]
Every single % in that file won't be read, no matter where in the
file
it is. Any solutions? This is terribly annoying since I need to
have
those percentage signs in my file.
Greetings,
Jan Van Boghout
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
Hasan Diwan
OpenPGP KeyID: 0x7EE3855B
Fingerprint: 42F0 5758 C3EB BA1F ABD2 ED49 3390 CCF0 7EE3 855B
http://www.cs.rpi.edu/~diwanh/gpg.key
[demime 0.98b removed an attachment of type application/pgp-signature
which had a name of PGP.sig]
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.