CMac command to go to nth occurence of a string in a line

Home Forums Multi-Edit User Created Macros CMac command to go to nth occurence of a string in a line

Tagged: 

This topic contains 3 replies, has 2 voices, and was last updated by  Clay Martin 1 year, 2 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #21992

    Michael
    Participant

    I am trying to find a function to do what I need, but can’t find it.

    What I want to do is, from the end of a line, come back to the 7th occurrence of a comma (I am trying to add double quotes to a CSV file).

    Does such a command exist in CMac?

    #21993

    Clay Martin
    Keymaster

    Hi,
    While there is no specific command to do that, you could do it with a loop using a search that is restricted to the same line. Find_text has a parameter that allows you to specify the number of lines to search. You could move the cursor to the beggining of the line, then search that line for a comma, seven times, then make your substitution.

    I am certain that you could do this with a perl regular expression,but I am not so good with those. You might be able to do this with a unix regular expression like:
    (.+,.+,.+,.+,.+,.+,.+,)(.+)(,.*)
    replace
    \1″\2″\3

    Hope that helps,
    Clay

    #21994

    Michael
    Participant

    Hi Clay,

    Thanks for the reply.

    Does Find_text have a mode where it uses the current line? something like

    EOL;
    for(i=1; i++; i=7) {
    Find_Text(curr_line, ‘,’,1,_Backward)
    }

    #21997

    Clay Martin
    Keymaster

    Hi,
    You can just use 1 as the line count parm and it will stay on the line.
    Find_Text( ‘,’, 1, _Backward) integer function
    Though you may want to test the result of Find_Text for success in case the line runs out of commas before 7 are found.

    You may find additional info if you open the Cmac language help file and search for Search And Replace Function List.

    Thanks,
    Clay

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.