Parser Support

  • Hi List,

    Do we have any parser to parse a file with the following entries?

    ID String ID Actual String
    11111=STRINGLITERAL_ID_1=String 1 some Blah
    11112=STRINGLITERAL_ID_2=String 2
    11113=STRINGLITERAL_ID_3=String 3
    ..
    ..

    Basically I need to construct two dictionaries from that file. One with 'ID' vs 'Actual String' as Key-Value pairs and  second one with 'String ID' Vs 'Actual String' as Key-Value pairs.

    - Apparao Mulpuri

    This email and any attachments are confidential, and may be legally privileged and protected by copyright. If you are not the intended recipient dissemination or copying of this email is prohibited. If you have received this in error, please notify the sender by replying by email and then delete the email completely from your system. Any views or opinions are solely those of the sender. This communication is not intended to form a binding contract unless expressly indicated to the contrary and properly authorised. Any actions taken on the basis of this email are at the recipient's own risk.
  • On 18 Jun 2012, at 08:22, Appa Rao Mulpuri wrote:

    > Hi List,
    >
    > Do we have any parser to parse a file with the following entries?
    >
    > ID String ID Actual String
    > 11111=STRINGLITERAL_ID_1=String 1 some Blah
    > 11112=STRINGLITERAL_ID_2=String 2
    > 11113=STRINGLITERAL_ID_3=String 3
    > ..
    > ..
    >
    > Basically I need to construct two dictionaries from that file. One with 'ID' vs 'Actual String' as Key-Value pairs and  second one with 'String ID' Vs 'Actual String' as Key-Value pairs.

    Core parse will trivially create one for you:
    https://github.com/beelsebob/CoreParse

    Bob
  • On Jun 18, 2012, at 12:22 AM, Appa Rao Mulpuri wrote:

    > Basically I need to construct two dictionaries from that file. One with 'ID' vs 'Actual String' as Key-Value pairs and second one with 'String ID' Vs 'Actual String' as Key-Value pairs.

    Do you even need a real parser for this? Parser generators are great, but they tend to have enough of a learning curve and runtime overhead that they may be overkill for something this simple.

    Just use -rangeOfString:options:range: to locate the first two "=" in each line, then grab the three substrings that they're separated by. (You could even use -componentsSeparatedByString:@"=" if you were 100% sure that the freeform text in the third field never contains an "=".)

    Or, on 10.7/iOS5, you can use NSRegularExpression.

    —Jens
previous month june 2012 next month
MTWTFSS
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30  
Go to today