Re: NSString is cutting off characters
Re: NSString is cutting off characters
- Subject: Re: NSString is cutting off characters
- From: publiclook <email@hidden>
- Date: Sun, 16 Feb 2003 17:34:21 -0500
On Sunday, February 16, 2003, at 04:39 PM, Brian Ganninger wrote:
>
So no matter what I try I cannot figure out a way to dynamically
>
generate a
>
string to access the files inside the app's bundle.
>
>
Help in this very frustrating matter would be greatly appreciated, as
>
I'm
>
about ready to throw my PowerBook through my wall, which really
>
wouldn't be
>
a good path at all for anything :-P
>
>
- Brian Ganninger
>
_______________________________________________
To start with, the line gaugePath = [[NSString alloc]
initWithString:percentUsed]; is completely useless in your example.
Your problem is probably that you are incorrectly outputting gaugePath
with NSLog() and NSLog() is removing a character because it thinks you
are specifying a format. Do you perhaps really have a formatting
character like '%' in your percentUsed string and you neglected to
mention that ?
The following program uses several different techniques to achieve your
goal and succeeds every time:
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
// technique 1
{
NSString *gaugePath = [@"87"
stringByAppendingPathExtension:@"tif"];
NSLog(@"%@", gaugePath);
}
// technique 2
{
int anInteger = 87;
NSString *gaugePath = [NSString stringWithFormat:@"-.tif",
anInteger];
NSLog(@"%@", gaugePath);
}
// technique 3
{
NSString *percentUsed = @"87";
NSString *gaugePath = [NSString stringWithFormat:@"%@.tif",
percentUsed];
NSLog(@"%@", gaugePath);
}
// technique 3
{
NSString *percentUsed = @"87";
NSString *gaugePath = [NSString stringWithFormat:@"%@%@",
percentUsed, @".tif"];
NSLog(@"%@", gaugePath);
}
// technique 3
{
NSString *percentUsed = @"87";
NSString *gaugePath = [percentUsed
stringByAppendingPathExtension:@"tif"];;
NSLog(@"%@", gaugePath);
}
[pool release];
return 0;
}
The following program reproduces your problem by misusing NSLog():
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
// technique 3
{
NSString *percentUsed = @"‡";
NSString *gaugePath = [percentUsed
stringByAppendingPathExtension:@"tif"];;
NSLog(gaugePath);
}
[pool release];
return 0;
}
You could have spent the five minutes concocting the same tests I
provided in this email...
_______________________________________________
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.