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

sm4ck

macrumors newbie
Original poster
Dec 2, 2009
8
0
OK, I think this is a very stupid problem but it is driving me nuts and I just can't figure out what the problem is (probably too much eggnog over the holidays). I'm trying to create a NSString from two other NSStrings and it seems like everything over a certain number of characters gets cut off.

Code:
  // Convert texture name to NSString
  NSString *ns_texture_name = [NSString stringWithCString:texture_name length:strlen(texture_name)];  
  
  // Get the path
  NSString *ns_path = [[NSBundle mainBundle] pathForResource:ns_texture_name ofType:@"tga"];

  // NSString *full_path = [NSString stringWithFormat: @"%@/%@.tga", ns_path, ns_texture_name];
  NSString * full_path = [[NSString alloc] initWithFormat:@"%@/%@.tga", ns_path, ns_texture_name];

Everything seems to be working but the texture name and ".tga" do not get appended to the path. I have tested with two shorter strings and they get concatenated as expected.

Very frustrating, any help would be appreciated.

Thanks!
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
A few comments:

Don't use stringWithCString:length: it's deprecated. Use stringWithCString:encoding: if you must, or stringWithUTF8String:, which is pretty much the same thing.

Don't manipulate paths in that way. Use the methods in NSPathUtilities.h, like stringByAppendingPathComponent and stringByAppendingPathExtension. Those are easier to use.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.