Please Help NSString Cutting off Characters

Discussion in 'iOS Programming' started by sm4ck, Dec 30, 2009.

  1. sm4ck macrumors newbie

    Joined:
    Dec 2, 2009
    #1
    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!
     
  2. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    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.
     

Share This Page