How do I find the endline character in IL instructions RRS feed

  • Question

  • HI everyone,

    I am making a custom rule to look at LOC for a particular code, now..I have the count of all Opcodes however that is different from line of code, we want to know how many lines are there in the code.

    My Question here is how do I figure that the opcode belongs to separate line and not count all the opcodes.



    • Edited by Shivangi_K Wednesday, June 3, 2015 11:57 AM minor spelling mistake
    Wednesday, June 3, 2015 11:57 AM


  • A line in a text file, generally speaking, will end with a combination of the character codes 13 (carriage-return) and 10 (line-feed). The reason for this goes way back to the early days of computers when the only output was to printers. Actually the terminology goes back fifty years before that to type-writers. The carriage-return would move the print head the beginning of the line, and the line-feed would move the paper up to a new line.

    Back in the early days of the PC, an easy way to mess with someone would be to reverse the combination (10,13 instead of 13-10). The early world processors would choke on the files, and some would even crash.

    This little program will load the entire file in, check each character in in the file, and count the line feeds; giving you the number of lines in the file.

    'Count the lines in the file
    filename = Program.Directory
    filename = filename + "\textfile.txt"
    'Pull in the entire file
    contents = File.ReadContents(filename)
    'Look at every character in the file one by one
    For i = 1 To Text.GetLength(contents)
      character = Text.GetSubText(contents,i,1)  'pull a character out
      code = Text.GetCharacterCode(character)    'get its character code
      TextWindow.Write(code + " = ")
      if code < 32 then 'do not try to display non-printable characters
      TextWindow.Write(",  ")
      If code = 10 Then            'Was this a line feed character?
        linecount = linecount + 1  'Add one to the count.
    TextWindow.WriteLine("There are " + linecount + " lines in the file")

    Now in the modern world of the internet, not all text files will have both the carriage-return and the line-feeds together. Although most will have at least the line-feed character, and nearly all of them will have one or the other.

    I hope helps.  :-)

    Wednesday, June 3, 2015 1:18 PM