Saturday 15 March 2014

ios - Can't compare NSData header to string in Swift -


I am trying to compare the header against the string (the first bytes of NSDT), I can print the string successfully I'm doing the comparison, but I'm not working.

I have tried it:

  var dataHeader: NSString = NSString (bytes: data.bytes, length: min (data.length, 8), encoding: NSASCIIStringEncoding )! Println (dataHeader) Results: PK  

The ASCI of "PK" is 0x50 0x4b.

When I try the following, nothing happens:

  if the data header == "PK" {}  

Maybe I'm a Noble but I have no idea left, so how should anyone know how to solve it? I'm guessing that there is something to do with string encoding, but after doing so many research, I still can not figure it out.

Any help is appreciated, thanks!

Is it possible that there are other non-print characters after "PK" if this is binary data ? The

If the data header hasPrefix ("PK") {// do something}

No comments:

Post a Comment