iphone - What are these Strange 'rogue characters' at the end of my NSString? -


I have a text file (songlist.txt) that retrieves my app from the server and stores locally when If I try to use the contents of the file in my app then I am getting unexpected results. When I looked into the issue, I came to know that strange characters were sometimes appearing at the end of the text file's NSSTING content.

Why are these funny characters? (Below is my source):

Example of Strange characters at the end of the string:

1) I
2) upp †
) Mul †
4) ID

// Text file exact content (songlist.txt)

Song Forest. Mp3
two songs MP3
Three song MP3
song four.m.pe. P.


Downloading a list of songs from the Internet, saving it to the Documents folder - (zero) Download Songlists {NSString * songlistString; NSString * URLString_list = @ "http://et.bicdoss.com/app/songlist.txt"; NSURL * URL_list = [NSURL URL YouthString: [URL string_style stringbadingproperAsspuping encoding: NASCitit encoding]]; // Get the data of content (for writing on disk) NSData * songData = [NSData dataWithContentsOfURL: URL_list]; If (songdata == zero) {NSLog (@ "SONGLIST.TXT not downloaded"); } Else {// Written in Songlist.txt on disk NSString * filePath = [[Self Document Directory] stringByAppendingPathComponent: @ "music / songlist.txt"]; [SongData writeToFile: File path atomically: Yes]; NSLog (@ "Songlist .text download"); }} // retrieve songlist.txt from the local documents folder - (NSString *) getLocalSongList {NSData * textFileData = [NSData dataWithContentsOfFile: [[self documentsDirectory] stringByAppendingPathComponent: @ "music / songlist.txt"]]; NSString * textFileString = [NSString string withUTF8 string: [textFileData bytes]]; Return text filestring; } // Create NSMutableArray of content of songlist.txt (separated by linebreaks) ... NSMutableArray * files_catalog; Files_catalog = [[NSMutableArray alloc] init]; [Files_catalog addObjectsFromArray: Separate String from [[Auto-MeetGlist] Components: @ "\ n"]]; [Files_catalog retain]; (Int a = 0; a & lt; [files_catalog count]; a ++) {nslog (@ "object's content% i (files_catalog)% @", a, [files_catalog objectsoutx: a]); / * Note: The above NSLog statement always gives weird output (note strange characters at the end of the last filename :) (Output) 2010-02-02 21: 22: 27.145 Some apps [19670: 207]> gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; Objct 0 (files_catalog) Cntnts of Song One.mp3 2010-02-02 21: 22: 27.145 SomeApp [19,670: 207] & gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; Objct 1 (files_catalog) Song of Two.mp3 2010-02-02 of Cntnts 21: 22: 27.146 SomeApp [19,670: 207] & gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; Objct 2 (files_catalog) Songs of Three.mp3 2010-02-02 of Cntnts 21: 22: 27.146 SomeApp [19,670: 207] & gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; Objct 3 (files_catalog) Songs of Four.mp3 2010-02-02 of Cntnts 21: 22: 27.146 SomeApp [19,670: 207] & gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; CCTT Song Five of Objct 4 (files_catalog) MPPPL were some other examples of strange characters in the end: I upp † mul † ID * /}

It seems that the encoding is happening when you import encoding: Error: stringWithContentsOfFile attempts to use the method

  [NSString stringWithContentsOfFile: [[Self documentsDirectory ] StringByAppendingPathComponent: @ "music / songlist.txt"] Encoding: NSUTF8StringEncoding Error: Zero].  

Plus it leaves NSData step.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -