FW: NSString is cutting off characters
FW: NSString is cutting off characters
- Subject: FW: NSString is cutting off characters
- From: Brian Ganninger <email@hidden>
- Date: Sun, 16 Feb 2003 17:16:06 -0600
A big thanks to Nat! for pointing out a solution to my prob (and thanks to
Ali for his as well) I need to look back and see exactly where the problem
came from so I can avoid it in the future (I think it's exactly where Ali
pointed it out).
As Nat said:
"Sounds like you accidentally typed in some invisible junk into your
string that PB isn't showing.
try copy/pasting the line from email back to your source and rerun.
Also your code is leaking, because the reference to the "percentUsed"
string is forgotten, but the string isnt' autoreleased. Rather use
gaugePath = [NSString stringWithString:percentUsed];
gaugePath = [gaugePath stringByAppendingPathExtension:@"tif"];
or even simpler
gaugePath = [percentUsed stringByAppendingPathExtension:@"tif"];
"
Sorry for inflicting leaking code, it's a habit I need to break, but I cut
my teeth a long time ago on Java and got used to its gc. I'll definitely be
going through with a malloc-toothed comb before I release my app :-)
- Brian Ganninger
On 2/16/03 4:10 PM, "Ali Ozer" <email@hidden> wrote:
>
> gaugePath = [[NSString alloc] initWithString:percentUsed];
>
> gaugePath = [gaugePath stringByAppendingPathExtension:@"tif"];
>
>
>
> So the simplest solution would seem to be, make a new string with the
>
> percentUsed string and add the path extension. Pass that as the path
>
> to a
>
> method call looking inside the bundle, and I can get an numbered image
>
> that
>
> way (which is what I'm going for, without declaring 100 static strings
>
> to be
>
> able to have a solid path)
>
>
>
> But, when I run the above code, or any other stringAppending technique
>
> I
>
> could find, the following is what happens:
>
> 87.if
>
>
Do you have a "%" character in your percentUsed string, and later, are
>
you using it as a format string someplace, like perhaps in your NSLog?
>
See:
>
>
NSString *gaugePath = [[NSString alloc] initWithString:@"87%"];
>
gaugePath = [gaugePath stringByAppendingPathExtension:@"tif"];
>
NSLog (gaugePath);
>
NSLog (@"%@", gaugePath);
>
>
you get:
>
>
87.if
>
87%.tif
>
>
That's because when a string with "%" is used in places where
>
formatting characters are taken into account, it will be swallowed...
>
>
Ali
------ End of Forwarded Message
_______________________________________________
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.