Fwd: Problems with NSFileHandle and à/ò/ì... chars
Fwd: Problems with NSFileHandle and à/ò/ì... chars
- Subject: Fwd: Problems with NSFileHandle and à/ò/ì... chars
- From: Daniele Malcom <email@hidden>
- Date: Sun, 3 Oct 2004 11:06:42 +0200
---------- Forwarded message ----------
From: Daniele Malcom <email@hidden>
Date: Sat, 2 Oct 2004 10:48:56 +0200
Subject: Fwd: Problems with NSFileHandle and à/ò/ì... chars
To: email@hidden
---------- Forwarded message ----------
From: Daniele Malcom <email@hidden>
Date: Sat, 2 Oct 2004 09:27:43 +0200
Subject: Problems with NSFileHandle and à/ò/ì... chars
To: email@hidden
Hi list,
I'm making a newsgroup program and I need to store some particular
information about each received articles in a special index file. This
index file is composed by records of fixed length and each variable of
a record is of fixed length.
To reach ti length sometimes (when string length < fixed tag length) i
need to append to the string empty spaces with this method:
+ (NSString *) formatWithFixedLength:(int) length source:(NSString *) src {
int len = [src length];
if (len > length) return [src substringWithRange:
NSMakeRange(0,length)];
else {
NSString *tmp = [[NSString alloc] initWithString: [NSString
stringWithFormat: @"%@%@",src,[EMPTY_SPACES substringWithRange:
NSMakeRange(0,length-len)]]];
return [tmp autorelease];
}
}
(EMPTY_SPACES is a #defined NSString with 360 spaces chars).
Well, now I have fixed all tags and I need to save it using this method.
... open NSFileHandle...
[self _writeStringToHandle: fileHandle string: [self
formatWithFixedLength: AUT_LENGTH source: auth]];
...
writeStringToHandle simply does it:
+ (void) _writeStringToHandle:(NSFileHandle *) _handle
string:(NSString *) _string {
[_handle writeData: [_string dataUsingEncoding: NSISOLatin1StringEncoding]];
}
All seems to be ok but when I try to write a string like this "hello
hèllò hello" NSFileHandle can't write it to the file and my record
format become wrong.
Where is the problem? ISOLatin1 can support this chars òòòààà!!
ASCIIEncoding supports it, but why NSFileHandle can't write them!?
PS: I have tried using UNICODE but with this format I can't make a
fixed length records because it takes more than a byte for each
char... :-/
TIA
daniele
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden