Results 1 to 9 of 9

Thread: string with symbols to integer?

  1. #1
    Join Date
    Aug 2008
    Location
    Finland
    Posts
    2,851
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default string with symbols to integer?

    how to i turn a string with a "," in it into an integer?
    SCAR Code:
    GetTextatex(x+70, y, 0, SmallChars, false, false, 0, 3, 0, i, true, tr_AllChars);

    Im making a GetCurrentXp('skill'); function and that GetTextatex reads the experiencetext correctly, but it has commas like 332,123 Xp. I tried putting range to tr_Digits, but then it was like 332 123. (with space instead of a comma)
    How do i turn "332 123" or "332,123" into integers? no matter which

    Here's the function as it is now.
    SCAR Code:
    function GetCurrentXp(skill: string): integer;
    var XP : string;
    XPint, x, y: integer;
    begin
     HoverSkill(skill, false);
     FindText(x, y, 'Current', SmallChars, MIX1, MIY1, MIX2, MIY2);
     XP := GetTextatex(x+70, y, 0, SmallChars, false, false, 0, 3, 0, 15, true, tr_AllChars);
     writeln('Current xp = '+XP);
     XPint := strtoint(XP);
     result := XpInt;
    end;
    Its ALMOST working ^^ as mentioned, it gets the xp as a string correctly.

  2. #2
    Join Date
    Feb 2006
    Location
    Helsinki, Finland
    Posts
    1,395
    Mentioned
    30 Post(s)
    Quoted
    107 Post(s)

    Default

    SCAR Code:
    function GetCurrentXp(Skill: string): Integer;
    var
      XP: string;
      x, y: Integer;
    begin
      HoverSkill(Skill, False);
      FindText(x, y, 'Current', SmallChars, MIX1, MIY1, MIX2, MIY2);
      XP:= GetTextAtEx(x + 70, y, 0, SmallChars, False, False, 0, 3, 0, 15, True, tr_AllChars);
      WriteLn('Current XP = ' + XP);
      Result:= StrToInt(Replace(XP, ',', ''));
    end;

    ?

  3. #3
    Join Date
    Aug 2008
    Location
    Finland
    Posts
    2,851
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    AASD edited didn't notice your marks on the script

  4. #4
    Join Date
    Feb 2006
    Location
    Helsinki, Finland
    Posts
    1,395
    Mentioned
    30 Post(s)
    Quoted
    107 Post(s)

    Default

    Edit: No problem

  5. #5
    Join Date
    Aug 2008
    Location
    Finland
    Posts
    2,851
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    YESS THANKYOU! I had to add 1 more replace there, but now it works.
    XP := Replace(Replace(GetTextatex(x+70, y, 0, SmallChars, false, false, 0, 3, 0, 15, true, tr_AllChars),',',''),' ','');

    Well that's a short function isnt it

  6. #6
    Join Date
    Feb 2006
    Location
    Helsinki, Finland
    Posts
    1,395
    Mentioned
    30 Post(s)
    Quoted
    107 Post(s)

    Default

    You could also have something like this:

    SCAR Code:
    function GetCurrentXp(Skill: string): Integer;
    var
      XP: string;
      x, y: Integer;
    begin
      try
        HoverSkill(Skill, False);
        FindText(x, y, 'Current', SmallChars, MIX1, MIY1, MIX2, MIY2);
        XP:= GetTextAtEx(x + 70, y, 0, SmallChars, False, False, 0, 3, 0, 15, True, tr_AllChars);
        WriteLn('Current XP = ' + XP);
        Result:= TrimLetters(TrimOthers(XP));
      except
        WriteLn('Unable to get XP :(');
      end;
    end;



    Or like you just posted:

    SCAR Code:
    XP:= TrimLetters(TrimOthers(GetTextatex(x + 70, y, 0, SmallChars, False, False, 0, 3, 0, 15, True, tr_AllChars)));

    I say use TrimLetters with TrimOthers rather than Replace Works better!

  7. #7
    Join Date
    Aug 2008
    Location
    Finland
    Posts
    2,851
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    Thanks mate I'll post it to SRL function suggestions, and give you a great credit.

    EDIT:
    that last edit you suggested gives
    Line 15: [Error] (16234:37): Type mismatch in script
    I think i stay with that ugly function with 2 replaces

  8. #8
    Join Date
    Feb 2006
    Location
    Helsinki, Finland
    Posts
    1,395
    Mentioned
    30 Post(s)
    Quoted
    107 Post(s)

    Default

    You are welcome, I don't really need credit though.. You did all the work. I am just glad I could help

    Thanks though

  9. #9
    Join Date
    Apr 2007
    Location
    Perth, Australia
    Posts
    3,926
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    Instead of TrimLetters then TrimOthers you could just do GetNumbers?

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 5
    Last Post: 03-30-2008, 01:40 PM
  2. String to integer?
    By XcanadamanX in forum Web Development
    Replies: 5
    Last Post: 08-28-2007, 04:24 AM
  3. function SendKeyboard(FKey:Integer; Text:String): Integer;
    By Daniel in forum Research & Development Lounge
    Replies: 4
    Last Post: 07-18-2007, 04:28 PM

Posting Permissions

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