Question

I have a bunch of test cases in an XML file named : blah_blah_blah_blah_number

The test cases have the numbers all messed up like:

blah_3
blah_1
blah_7
....

I need to re-number them. So that the first one gets renumbered 1, the second 2.. and so on. I want to build a macro for this but I don't know how to start. I need some sort of search function that can go to the pattern I give it, and then it substitutes the number with a count that I keep in some variable. I'm not proficient at all with Slick-C, and would like to get this done quickly :\

Any help appreciated,

Ted

Was it helpful?

Solution

For a more timely answer, you might consider the SlickEdit forums on slickedit.com, but I'll try here.
I would load the file in a buffer, and create a macro along the following lines:

  • Create a while loop incrementing a counter
  • In the while loop, use search with regular expressions to find the next occurrence
  • When the next occurrence is found, use search_replace to replace the string found with a new string composed using the counter variable, and to repeat the previous search
  • When nothing is to be found any more, terminate the loop

Without testing it on an XML file, this should give you a start for your function (assuming you know how to create a macro file and load it into SE), a quick test showed it to work on a plain text file, no guarantees, however:

/* Demo for StackOverflow question 14205293 */
_command my_renumber() name_info(','VSARG2_MARK|VSARG2_REQUIRES_EDITORCTL)
{
  int not_found = 0; /* boolean to terminate loop */
  int iLoop = 0;     /* Counter to renumber items */

  /* Use search initially; if that call doen't find an item, we're done. */
  if (search('blah_:i', 'R') != 0)
  {
    not_found = 1;
  }

  while (!not_found)
  {
    if (search_replace('blah_' :+ iLoop, 'R') == STRING_NOT_FOUND_RC)
    {
      not_found = 1;
    }
    iLoop++;
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top