Character position



  • Is there a way to navigate to a specific column ( character position ) in a line of text. I have an error message in a program telling me that the error occur at line x, column 198. Icopied the text line to Notepad++ hopimg that I could easily identify the character at position 198.

    Can anyone help?



  • Well, what I would do if I needed to do this once or twice would be to put the caret on the line and then hold the right arrow key until the “Col:” in the status bar says “Col: 198”. Of course this seems so obvious maybe I am missing something.



  • If this is the only line in this document you could do
    ctrl+home
    ctrl+g
    mark offset (needs to be done once only)
    type column number
    enter

    Cheers
    Claudia



  • Hello Greg,

    Once again, regular expressions are very useful, concerning your problem :-)) Suppose that you get the warning : An error occurred, at line 38, column 198 !

    Simply, in the concerned document :

    • Get back to the very beginning of the file ( CTRL + Origin )

    • Open the Find dialog ( CTRL + F )

    • Select the Regular expression search mode

    • In the Find What zone, type (?-s)(.*\R){37}.{197}\K

    • Click on the Find Next button or hit the Enter key

    => A small calltip, with the indication ^ zero length match, appears, on line 38, at column 198 !

    Voilà !

    Notes :

    • Always locate your cursor at the beginning of your file, first

    • I wrote the two numbers 37 ( = 38 - 1 ) and 197 ( = 198 - 1 ). So, the general regex, to reach the column c of the line n, is (?-s)(.*\R){n-1}.{c-1}\K

    • The \K syntax, at the end of the regex, means that the regex engine forgets the selection of the 37 first lines, as well as the 197 first characters of line 38. So, that regex match a zero-length string, located between columns 197 and 198, of the line 38 !

    • The in-line modifier (?-s), at the beginning of the regex, forces the regex engine to consider the dot meta_character as a standard character, only, even if you, previously, checked the . matches newline option of the Find dialog

    Remark :

    • If your program contains leading tabulations, instead of spaces, that regex will NOT reach the correct location, as any tabulation counts for a single character, although it lies on 2, 4, … spaces !

    Best Regards,

    guy038



  • @guy038
    hello guy038 ,
    I really want to know where to learn those regex syntax. The wiki page of notepad++ (http://docs.notepad-plus-plus.org/index.php/Regular_Expressions) contains several errors, and I don’t find the syntax “(?-s)” that you’re using. Where did you learn it?
    By the way, is there a way to sign in the wiki page, in order to edit the page? I only find “log in” on the upper-right, and don’t see how to register.
    I know I should’ve posted this whole thing in “General Discussion” of notepad++ community, but I have problem making “new Topic” at the moment. So I’m Replying here.
    Best regards.



  • The mentioned wiki page actually contains links to sites with the information you’re requesting.


Log in to reply