Results 1 to 4 of 4

Thread: Function ReplaceRegex2 and Debug

  1. #1
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default Function ReplaceRegex2 and Debug

    I decided to make a quick and easy general debugging function that (at the moment) returns the begins, end, repeats and untils in a script as an integer in an array (with begin 0, end 1, repeat 2 and until 3). Also, it includes ReplaceRegex2, which, as far as I know, works in the same way replace regex, except it returns how many times it replaced something (in the variable count).

    ReplaceRegex2:
    SCAR Code:
    function ReplaceRegex2(Txt,Regex,ReplaceStr: string; var count: integer): string;
    var
      RPos,RLen: integer;
     
    begin
      repeat
        RLen:= Length(Regex);
        RPos:= RegexPos(Txt,Regex);
        if(RPos = -1) then
          Break;
        Delete(Txt,Rpos,RLen-1);
        Insert(ReplaceStr,Txt,RPos);
        Inc(Count);
      until(count >= 1000);
      Result:= Txt;
    end;

    Debug:
    SCAR Code:
    function Debug(fileloc: string; var output: array of integer):Boolean;
    var
      iFile: Integer;
      sFile: String;
     
    begin
      SetArrayLength(output,4);
      iFile:= OpenFile(fileloc,false);
      ReadFileString(iFile,sFile,filesize(iFile));
      CloseFile(iFile);
      sFile:= Lowercase(sFile);
      ReplaceRegex2(sFile,'begin','<egi>',Output[0]);
      ReplaceRegex2(sFile,'end','<n>',Output[1]);
      ReplaceRegex2(sFile,'repeat','<epea>',Output[2]);
      ReplaceRegex2(sFile,'until','<nti>',Output[3]);
    end;

    You would use replaceregex2 the exact same way, excpet you put an integer to store the replaces in.
    E.g.
    SCAR Code:
    Writeln(ReplaceRegex2('Moo Quack Cluck','Moo','Quack',Moos)+' and '+IntToStr(Moos)+' moo/s');
    would give you: 'Quack Quack Cluck and 1 moo/s' in the debug log.

    Debug would be used as:
    SCAR Code:
    Debug(ScriptPath+'newscript.scar',debugArray);
    Writeln('You have '+IntToStr(debugArray[0])+' begin/s');
    or
    SCAR Code:
    Writeln('You have '+IntToStr(debugArray[1]-debugArray[0])+' more end/s than begins';

    That should explain the general idea of them. If you have any question, feel free to ask.

  2. #2
    Join Date
    May 2007
    Location
    NSW, Australia
    Posts
    2,823
    Mentioned
    3 Post(s)
    Quoted
    25 Post(s)

  3. #3
    Join Date
    Jul 2007
    Posts
    1,431
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Mhhh...

    Hmm...

    Nice dude, I'd love to see you in members...

    Your functions seems nice, but it's useful only peoples who can't script, or forgot keywords all the time

    By the way, standards, repeat and until is same as begin & end

    Where did you find out those commands?
    [CENTER][SIZE="4"]Inactive[/SIZE]I forgot my password[/CENTER]

  4. #4
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    Put together ReplaceRegex2 for Debug, so only added it because I thought someone might find it useful (will fix it after this).
    I'll hopefully be entering a script soon, only problem is I don't know what to do. I was going to make a powercutter, but there's a lot of them already and I want to make an 'original' script.
    Also, what commands are you talking about? OpenFile etc. I learned from a tutorial and found the RegexPos etc. in the scar help when checking if there was already a Regex counter.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replacing debug box
    By Negaal in forum OSR Help
    Replies: 0
    Last Post: 01-31-2008, 08:36 PM
  2. debug talker
    By HarryJames in forum First Scripts
    Replies: 2
    Last Post: 12-05-2007, 06:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •