Objc-DataFile-Unreadable Substring-Unknown to any encoding

65 Views Asked by At

I have a DataFile, built by subsidiairy Application. I need to locate some substring contained in the data file. They are identifiable by the character symbols delimiting them. For instance : *!substringqSxt .The substring will vary from a project to another so I need to locate the symbols delimiting them to read the following substring. I also printed the file to different encodings trying which one was used and matched the original data file. found it was MacOsRomanStringEncoding.

I use NSRange:rangOfStringto locate the delimiting symbols. Here is my code :

char *debutAudio ="jjbj";
char *finAudio ="qSxt";

NSString *debutAudioConverted = [[NSString alloc]
                                 initWithCString: debutAudio
                                 encoding:NSMacOSRomanStringEncoding];
NSString *finAudioConverted = [[NSString alloc]
                               initWithCString: finAudio
                               encoding:NSMacOSRomanStringEncoding];


NSRange debutaudioRange =[dataFileContent rangeOfString:debutAudioConverted];
NSRange finaudioRange =[dataFileContent rangeOfString:finAudioConverted];


NSLog(@"range is %@",NSStringFromRange(debutaudioRange));
NSLog(@"range is %@",NSStringFromRange(finaudioRange));

Both NSLog returns range is {9223372036854775807, 0} so not locating the delimiting strings there.

And if I ask to look for other strings contained in the file like "Settings" the rangeOfString will return the proper location and length.

I thought the file may contain multiple encodings, and tried converting with initWithCStringto any possible encoding but nothing would do.

Also if I open the file in text edit and use the "Find" function, it will not locate the delimiting string, but will locate other words. My guts tell me its related. I dont know where to look for info. Could the file be protected, I am reading a copy of it though.

1

There are 1 best solutions below

0
On

I have found the problem occuring here. The proper encoding is still MacOsRoman. The problem is the prefix string *debutAudio "jjbj"there is actually a tiny space , like a quarter space between each characters. I have tried every unicode spaces listed here :https://www.cs.tut.fi/~jkorpela/chars/spaces.html#adj without any success. Now I will tried to find some half or quarter space under MacOsRoman see if that is working.