Results 1 to 12 of 12

Thread: Removing text from a string

  1. #1
    Join Date
    Oct 2008
    Posts
    196
    Mentioned
    1 Post(s)
    Quoted
    20 Post(s)

    Default Removing text from a string

    Working on my first script but couldn't get past this obstacle:
    I'm trying to remove a peice of text from a string. e.g.:
    I've got the string "1 2 g p" and I'm trying to remove all the text from it and end up with the numbers so I can convert it to an integer and use it for something else. I'm trying to figure out how to remove the " g p" part. Is there an already made function in SRL to do this? if not, can someone give me some hints of how to achive it

    thanks a lot

    edit:
    Simba Code:
    program new;
     var
     text: string;
     int: integer;
    begin
    text := GetTextAtEx(296, 186, 440, 199, 0, 0, 0, 6400255, 5, 'UpChars');
    int := StrToInt(text)
    Writeln(int);
    end.

    this is the code for retrieving the text, if anybody is interested

  2. #2
    Join Date
    Oct 2008
    Posts
    196
    Mentioned
    1 Post(s)
    Quoted
    20 Post(s)

    Default

    I've discovered the replace function but I don't know how to use it yet :S

    Simba Code:
    program new;
     var
     text, text1: string;
     int: integer;
    begin
    text := GetTextAtEx(296, 186, 440, 199, 0, 0, 0, 6400255, 5, 'UpChars');
    text1 := Replace(text, ' g p', '1');
    int := StrToInt(text1)
    Writeln(int);
    end.

  3. #3
    Join Date
    Jan 2008
    Location
    Ontario, Canada
    Posts
    7,805
    Mentioned
    5 Post(s)
    Quoted
    3 Post(s)

    Default

    GetNumbers!

    Can't find any reference guide at the moment, but its straight forward.
    Writing an SRL Member Application | [Updated] Pascal Scripting Statements
    My GitHub

    Progress Report:
    13:46 <@BenLand100> <SourceCode> @BenLand100: what you have just said shows you 
                        have serious physchological problems
    13:46 <@BenLand100> HE GETS IT!
    13:46 <@BenLand100> HE FINALLY GETS IT!!!!1

  4. #4
    Join Date
    Oct 2008
    Posts
    196
    Mentioned
    1 Post(s)
    Quoted
    20 Post(s)

    Default

    Made my function for finding the numbers but the problem with it is that it can't detect numbers above 999 for some reason :S

    Here's the script so you can have a look at it:

    Simba Code:
    program new;

    procedure Findnumber;
    var
     text, text1, text2: string;
     int: integer;

    begin
      text := GetTextAtEx(296, 186, 440, 199, 0, 0, 0, 6400255, 5, 'UpChars');
      text1 := Replace(text, ' g p', '', []);
      text2 := Replace(text1, ' ', '',  [rfReplaceAll]);
      int := StrToInt(text2);
      Writeln(int);
    end;

    begin
      ClearDebug;
      Findnumber;
    end.

    It always gives me "Error: Exception: "1000" is an invalid integer at line 10" with numbers 1000 or above

    Anyway, I'll try the Getnumber you sent me

  5. #5
    Join Date
    Feb 2006
    Posts
    3,044
    Mentioned
    4 Post(s)
    Quoted
    21 Post(s)

    Default

    Simba Code:
    function TrimLetters(s : string) : string;
    var
      LetterArray: TStringArray;
      i: Integer;
    begin
      LetterArray := ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o',
        'p','q','r','s','t','u','v','w','x','y','z', '.'];
      result := s;
      for i := 0 to Length(LetterArray) - 1 do
        result := Replace(result, LetterArray[i], '', [rfReplaceAll, rfIgnoreCase]);
    end;

    begin
    Writeln(TrimLetters('619237109 x Coins.'));
    end.


    Try that one.

    ~Home

  6. #6
    Join Date
    Nov 2010
    Location
    Australia
    Posts
    1,472
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    Use GetTextAtExWrap and see if that works. It works for me with numbers >999
    Or try changing the min spacing like so:

    StrToInt(GetTextAtExWrap(296, 186, 440, 199, 0, 10, 1, 6400255, 5, 'UpChars'));

  7. #7
    Join Date
    Oct 2008
    Posts
    196
    Mentioned
    1 Post(s)
    Quoted
    20 Post(s)

    Default

    That solved it. Thanks a lot, Homer

    Simba Code:
    program new;
    var
     text, text1: string;
     int: integer;

    function TrimLetters(s : string) : string;
    var
      LetterArray: TStringArray;
      i: Integer;
    begin
      LetterArray := ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o',
        'p','q','r','s','t','u','v','w','x','y','z', '.', ',', ' '];
      result := s;
      for i := 0 to Length(LetterArray) - 1 do
        result := Replace(result, LetterArray[i], '', [rfReplaceAll, rfIgnoreCase]);
    end;


    begin
      ClearDebug;
      text := GetTextAtEx(296, 186, 440, 199, 0, 0, 0, 6400255, 5, 'UpChars');
      text1 := TrimLetters(text);
      int := StrToInt(text1);
      Writeln(int);
    end.

    But now I'm left with another problem; I get this error when I try to include SRL in the script

    Code:
    [Error] (18:80): Invalid number of parameters at line 17
    Compiling failed.
    Simba Code:
    program new;
      {$i SRL/SRL.scar}
      {$i srl/srl/misc/grandexchange.scar}
    var
     text, text1: string;
     int: integer;

    function TrimLetters(s : string) : string;
    var
      LetterArray: TStringArray;
      i: Integer;
    begin
      LetterArray := ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o',
        'p','q','r','s','t','u','v','w','x','y','z', '.', ',', ' '];
      result := s;
      for i := 0 to Length(LetterArray) - 1 do
        result := Replace(result, LetterArray[i], '', [rfReplaceAll, rfIgnoreCase]);
    end;


    begin
      SetupSRL;
      ClearDebug;
      text := GetTextAtEx(296, 186, 440, 199, 0, 0, 0, 6400255, 5, 'UpChars');
      text1 := TrimLetters(text);
      int := StrToInt(text1);
      Writeln(int);
    end.

    The same also happens with the GetTextAtEx(....) function. It seems that both simba and SRL have the same function and there is now way that I know off to tell the scipt which function to use :S

  8. #8
    Join Date
    Oct 2008
    Posts
    196
    Mentioned
    1 Post(s)
    Quoted
    20 Post(s)

    Default

    Quote Originally Posted by KingKong View Post
    Use GetTextAtExWrap and see if that works. It works for me with numbers >999
    Or try changing the min spacing like so:

    StrToInt(GetTextAtExWrap(296, 186, 440, 199, 0, 10, 1, 6400255, 5, 'UpChars'));
    I'll try it and see if it works with SRL included

  9. #9
    Join Date
    Jan 2011
    Location
    Denver, CO
    Posts
    1,351
    Mentioned
    2 Post(s)
    Quoted
    72 Post(s)

    Default

    Just rename TrimLetters

    E: Heres mine
    Simba Code:
    function GetNumerals(const s: string): string;
    var
      i, j: Integer;
      numArray: array of string;
    begin
      numArray := ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
      for i := 1 to High(s) do
        for j := 0 to High(numArray) do
        begin
          if not (s[i] = numArray[j]) then Continue;
          Result := Result + s[i];
        end;
    end;
    Last edited by Echo_; 11-19-2011 at 02:13 PM.

  10. #10
    Join Date
    Oct 2008
    Posts
    196
    Mentioned
    1 Post(s)
    Quoted
    20 Post(s)

    Default

    Quote Originally Posted by Echo_ View Post
    Just rename TrimLetters
    The problem is with the replace function inside TrimLetters. Tried changing the name of Trimletters and got the same result


    @KingKong: Tried what you told me and it worked but as soon as I included SRL it gave me the same error as before.

    Simba Code:
    program new;
     {$i SRL/SRL.scar}
     {$i srl/srl/misc/grandexchange.scar}


    procedure Findnumber;
    var
     text, text1: string;
     int: integer;

    begin
      text := GetTextAtExWrap(296, 186, 440, 199, 0, 10, 1, 6400255, 5, 'UpChars');
      text1 := Replace(text, 'gp', '', []);
      int := StrToInt(text1);
      Writeln(int);
    end;

    begin
      SetupSRL;
      ClearDebug;
      Findnumber;
    end.

    Code:
    [Error] (14:39): Invalid number of parameters at line 13
    Compiling failed.
    fixing this is beyond my expertise



    Edit: Thanks to everyone for helping, I've just fixed it

    Simba Code:
    program new;
      {$i SRL/SRL.scar}
      {$i srl/srl/misc/grandexchange.scar}
    var
     text, text1: string;
     int: integer;

    function TrimLetters(s : string) : string;
    var
      LetterArray: TStringArray;
      i: Integer;
    begin
      LetterArray := ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o',
        'p','q','r','s','t','u','v','w','x','y','z', '.', ',', ' '];
      result := s;
      for i := 0 to Length(LetterArray) - 1 do
        result := Replace(result, LetterArray[i], '');
    end;


    begin
      ClearDebug;
      SetupSRL;
      text := GetTextAtExWrap(296, 186, 440, 199, 0, 10, 1, 6400255, 5, 'UpChars');
      text1 := TrimLetters(text);
      int := StrToInt(text1);
      Writeln(int);
    end.
    Last edited by HT BaaFly; 11-19-2011 at 02:14 PM.

  11. #11
    Join Date
    Jan 2011
    Location
    Denver, CO
    Posts
    1,351
    Mentioned
    2 Post(s)
    Quoted
    72 Post(s)

    Default

    Quote Originally Posted by HT BaaFly View Post
    The problem is with the replace function inside TrimLetters. Tried changing the name of Trimletters and got the same result


    @KingKong: Tried what you told me and it worked but as soon as I included SRL it gave me the same error as before.

    Simba Code:
    program new;
     {$i SRL/SRL.scar}
     {$i srl/srl/misc/grandexchange.scar}


    procedure Findnumber;
    var
     text, text1: string;
     int: integer;

    begin
      text := GetTextAtExWrap(296, 186, 440, 199, 0, 10, 1, 6400255, 5, 'UpChars');
      text1 := Replace(text, 'gp', '', []);
      int := StrToInt(text1);
      Writeln(int);
    end;

    begin
      SetupSRL;
      ClearDebug;
      Findnumber;
    end.

    Code:
    [Error] (14:39): Invalid number of parameters at line 13
    Compiling failed.
    fixing this is beyond my expertise
    Try mine since it doesn't use replace.

  12. #12
    Join Date
    Oct 2008
    Posts
    196
    Mentioned
    1 Post(s)
    Quoted
    20 Post(s)

    Default

    Alright, thanks turned out all I had to do was remove the '[]' in the replace function xD that was the only difference between the SRL and the simba versions lol

Thread Information

Users Browsing this Thread

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

Posting Permissions

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