Manipulating piped responses from NSTask

Discussion in 'Mac Programming' started by Denarius, Jul 15, 2008.

  1. Denarius macrumors 6502a

    Denarius

    Joined:
    Feb 5, 2008
    Location:
    Gironde, France
    #1
    This is the command and response I'm interested in dealing with:

    Code:
    PennyMBP:~ adam$ lpstat -v
    device for Brother_HL_1650_1670N_series___PennyG5: tea4cups:mdns://Brother%20HL-1650_1670N%20series%20%40%20PennyG5._ipp._tcp.local
    device for Canon_iP4500_series___PennyG5: tea4cups:mdns://Canon%20iP4500%20series%20%40%20PennyG5._ipp._tcp.local.
    device for EPSON_AL_C900___PennyG5: tea4cups:mdns://EPSON%20AL-C900%20%40%20PennyG5._ipp._tcp.local
    The reason I want this is I want to take the data, get rid of the 'device for.... [printername]: ' and just return the device URI for my printer object. Problem is I've scoured through the documentation for NSString and NSMutableString and was astounded to find nothing at all relating to regular expressions. Can anyone point me in the right direction with regard to a method for chopping off the bit of the string before the URI?
     
  2. Mac Player macrumors regular

    Joined:
    Jan 19, 2006
  3. Denarius thread starter macrumors 6502a

    Denarius

    Joined:
    Feb 5, 2008
    Location:
    Gironde, France
    #3
    So going with your second suggestion it would be something like(?):

    Code:
    NSRange *rangeToRemove=[textToManipulate rangeOfString:@":"];
    //move the location one on from the colon to the following empty space
    rangeToRemove.location++;
    //swap the location over to the length
    rangeToRemove.length=rangeToRemove.location;
    //set starting point at start of the string.
    rangeToRemove.location=0;
    NSString *manipulatedString=[stringToManipulate stringByReplacingCharactersInRange:rangeToRemove withString:@""];
     
  4. Denarius thread starter macrumors 6502a

    Denarius

    Joined:
    Feb 5, 2008
    Location:
    Gironde, France
    #4
    Actually, just been browsing through that RegexKit that you mentioned. Looks like it'll be very useful. Thanks for the heads up.
     
  5. numero macrumors regular

    Joined:
    Jul 23, 2002
    Location:
    OR
    #5
    Or you could pipe your result through awk before using the result.
     

Share This Page