Home > Community > Forums > Custom IC SKILL > read next line if first charcter is semicolon

Email

* Required Fields

Recipients email * (separate multiple addresses with commas)

Your name *

Your email *

Message *

Contact Us

* Required Fields
First Name *

Last Name *

Email *

Company / Institution *

Comments: *

 read next line if first charcter is semicolon 

Last post Tue, Apr 15 2014 7:57 AM by vuong. 4 replies.
Started by Rojalin 05 Sep 2012 03:58 AM. Topic has 4 replies and 953 views
Page 1 of 1 (5 items)
Sort Posts:
  • Wed, Sep 5 2012 3:58 AM

    • Rojalin
    • Top 200 Contributor
    • Joined on Wed, Nov 30 2011
    • Posts 41
    • Points 775
    read next line if first charcter is semicolon Reply

     

    Hi,

    I have a file.After importing i want to read this.I want if the first character in a line of the file is semicolon then it should read the next line.

    Is there any procedure to do that.

     

    Thanks 

     

    • Post Points: 20
  • Wed, Sep 5 2012 4:15 AM

    Re: read next line if first charcter is semicolon Reply

    What does the file look like? You might be able to use lineread() which uses the SKILL parser to read the file - and if it contains blank lines or SKILL-like comments, it will return t rather than the contents of the line...

    Andrew.

    • Post Points: 20
  • Wed, Sep 5 2012 4:25 AM

    • Rojalin
    • Top 200 Contributor
    • Joined on Wed, Nov 30 2011
    • Posts 41
    • Points 775
    Re: read next line if first charcter is semicolon Reply
    thanks But my concern is if first character of the file is semicolon then i dont want to read it. It should skip to the next line to read first character of that new line. File is .sexp file Thanks
    • Post Points: 20
  • Wed, Sep 5 2012 5:12 AM

    Re: read next line if first charcter is semicolon Reply

    I've no idea what ".sexp" file is, but if you had a file that looked like this (say):

    ; some comments
    a b c
    ; some more comments
    ; and some more
    /* and even
    some
    C-like comments */
    1 2 3 ; ignore this bit at the end of the line

    you could do:

    port=infile("myfile")
    when(port
      while(data=lineread(port)
        unless(data==t
          printf("elements on the line were: %L\n" data)
        )
      )
    )
    close(port)

    It will then output:

    elements on the line were: (a b c)
    elements on the line were: (1 2 3)

    You should read the documentatin on lineread. This won't work if it's not in SKILL-like syntax. If you want to general line-by-line reading and returning a string, you could do:

    port=infile("myfile")
    when(port
      while(gets(line port)
        unless(substring(line 1 1)==";"
           printf("The line that was read was: %s" line)
        )
      )
      close(port)
    )

    Then this outputs:

    The line that was read was: a b c
    The line that was read was: /* and even
    The line that was read was: some
    The line that was read was: C-like comments */
    The line that was read was: 1 2 3 ; ignore this bit at the end of the line

    Note that gets() will include the carriage return in the string that was read.

    So your mileage may vary - you can do whatever you want, but you'll just need to code it appropriately. You could also use the rex.* functions or pcre.* functions (in IC61X for pcre) to use pattern matching if that's easier.

    Regards,

    Andrew.

    • Post Points: 20
  • Tue, Apr 15 2014 7:57 AM

    • vuong
    • Top 75 Contributor
    • Joined on Mon, Jul 14 2008
    • Milpitas, CA
    • Posts 91
    • Points 350
    Re: read next line if first charcter is semicolon Reply
    Thanks
    Vuong Ho
    • Post Points: 5
Page 1 of 1 (5 items)
Sort Posts:
Started by Rojalin at 05 Sep 2012 03:58 AM. Topic has 4 replies.