Reading a TXT data file, from HTTP

Discussion in 'iOS Programming' started by Fontano, Sep 22, 2008.

  1. Fontano macrumors member

    Joined:
    Jun 27, 2008
    #1
    I have my app working with my REST webservices.
    However, the XML overhead is un-believably horrible on EDGE connections, so-so on 3G, and okay on Wi-FI (or when on the simulator).

    I have turned my REST service to output a deliminited TXT file instead of a well formed XML. This has resulted in a 92% drop in the file size.

    Is there a code sample out there, on what is the best way to read, load, and parse out the deliminted lines. So I can load them into my custom class objects that I am using in the current app.
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    Probably the simplest way is to load the whole file into a NSString then split the string into lines with componentsSeparatedByCharactersInSet: then split each line into components with the same...
     
  3. MarcVanH macrumors newbie

    Joined:
    Sep 12, 2008
    #3
    Here is code I used recently to parse out each line in a text file:

    Code:
               NSArray *fileData = [[NSString stringWithContentsOfFile:myFile] componentsSeparatedByString:@"\r\n"];
                for (NSString *dataLine in fileData) {
                    .....
    
    You could use the same code to parse each line of data - just change @"\r\n" to @",".
     
  4. Luke Redpath macrumors 6502a

    Joined:
    Nov 9, 2007
    Location:
    Colchester, UK
    #4
  5. iphonejudy macrumors 6502

    iphonejudy

    Joined:
    Sep 12, 2008
    #5
    Reading .txt file from http


    Hi,

    Have u solved this task,I also want to access a txt file from htttp(htttp://aaa/a/a.txt)

    Can u give me the code?

    Regards
    judy
     
  6. russellelly macrumors regular

    Joined:
    Jun 23, 2006
    Location:
    Glasgow, UK
    #6
    Code:
    NSString *urlContents = [NSString stringWithContentsOfURL:
    						   [[NSURL alloc] initWithString:
    							@"htttp://aaa/a/a.tx"]]; 
    should do the trick.
     

Share This Page