Results 1 to 18 of 18

Thread: A List Of All String Functions in SCAR ~ Naum

  1. #1
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default A List Of All String Functions in SCAR ~ Naum

    String Functions in SCAR



    Table of Contents

    I – Introduction
    II – List of String Functions and Usage in SCAR
    III – End Note




    I – Introduction


    Hello one and all, welcome to my tutorial on ‘String Functions in SCAR’. I haven't written many new tutorials, so I thought I'd write one. This tutorial is aimed at teaching intermediates about all of SCAR’s built in string functions. After this tutorial y’all should know about Text Editing and Text Reading, I will also touch on MD5 encryption - on how to load things and String encrypt in SCAR.



    II – List of String Functions and Usage in SCAR

    The Main String Function in SCAR is:

    procedure Writeln(s: string);
    Outputs text string to debug box.
    Usage :
    SCAR Code:
    Begin
      WriteLn('lol');
    end.
    Output : 'lol'
    ^ Just outputs what you put in, this is good for debugging. ^

    function copy(s: string; ifrom, icount: LongInt): string;

    Returns part of the string (Copy('abcde',2,3) would return 'bcd'.

    My Definition : ifrom is what positon in the text to start from, icount is how many characters to grab after that length : 'abcde' starts from the 2nd char (b) and counts 3 along after that (bcd) and copies it .

    Usage :
    SCAR Code:
    Begin
      WriteLn(Copy('This will copy "lol"', 17, 3));
    end.
    ^ Also remember that 'copy' counts spaces.

    It can also be stored in a variable.
    e.g
    SCAR Code:
    Var
      String1 : String;
    Begin
      String1 := Copy(Rs_GetUpText, 1, 4);
      MMouse(MMCX, MMCY, 70, 70);
      WriteLn(String1+' rune axe');
    end.
    ^ This should write in the debugbox : 'wield' (if you want to test you must have your mouse hovering over a rune axe');


    function pos(substr, s: string): LongInt;
    Returns position of substring in string. Returns 0 if not found.
    Usage :
    SCAR Code:
    Begin  
      ClearDebug;
      WriteLn('hi guys');
      If Pos('i', GetDebugText) = 2 Then
        WriteLn('we found "i" in the second position of the text');
    end.
    ^ Note that you must use Pos in conjuntion to an 'If <>= statement' ^
    A real time example:
    SCAR Code:
    Begin
      If Pos('lol', GetBlackText(8)) <> 0 Then
        Typesend('ha ha that was funny :)');
    end.
    ^ Pos is a clever way of finding text aswell as positions ^

    procedure delete(var s: string; ifrom, icount: LongInt);
    Refer back to 'copy' for this, uses the same principle but deletes a string instead of copying it
    Usage :
    SCAR Code:
    Var
      String1 : String;
    Begin
      String1 := 'hello haha goodbye';
      Delete(String1, 7, 4);
      WriteLn(String1);
    end.
    This would output : 'hello goodbye'
    ^ Note that it already modifies the variable so there is no need to make another one ^

    procedure insert(s: string; var s2: string; ipos: LongInt);
    Insert s into s2. ipos is the postion of the text in which to insert it in
    Usage :
    SCAR Code:
    Var
      String1 : String;
    Begin
      String1 := 'hello haha goodbye';
      Insert(' not funny', String1, 11);
      WriteLn(String1);
    end.

    function Between(s1, s2, s: string): string;
    Returns part of string s between substrings s1 and s2.
    Note : Personally I love this function, I think its really useful

    Usage :
    SCAR Code:
    Begin
      WriteLn(Between('the answer is :', '!!!', 'the answer is : 2!!!'));
    end.
    This would return : ' 2';

    function StrGet(var S: string; I: Integer): Char;
    Gets the string(S), character at the position(I).
    Usage :
    SCAR Code:
    program AutoTalkerMedium;

    const
      Word1 = 'This is our "first" string to send.';
      Word2 = 'This is our "second" string to send.';

    procedure SendString(text : string);
    var
      TempInt, TempInt1 : Integer;
      TempChar : Char;
    begin
      for TempInt := 1 to Length(text) do
      begin
        TempChar := StrGet(text, TempInt);//Here
        TempInt1 := GetKeyCode(TempChar);
        KeyDown(TempInt1);
        Wait(25 + Random(30));
        KeyUp(TempInt1);
        Wait(40 + Random(30));
      end;
      SendKeysVB('{ENTER}', True);
    end;

    begin
      SendString(Word1);
      SendString(Word2);
    end.
    ^ It is good for using in GetKeyCode, this is used in TypeSned ^


    function Uppercase(s: string): string;
    Returns the specified string in upper case (capitals).
    Usage :
    SCAR Code:
    Begin
      WriteLn(Uppercase('hey guyz'));
    end.
    OutPut : 'HEY GUYZ'

    function Lowercase(s: string): string;
    Returns the specified string in lowercase (non caps).
    Usage:
    SCAR Code:
    Begin
      WriteLn(lowercase('HEY GUYZ'));
    end.
    Output : 'hey guyz'

    function Trim(s: string): string;
    Removes spaces from start and end of string.
    Usage :
    SCAR Code:
    Begin
      WriteLn(Trim('    hello    '));
    end.
    Output : 'hello'


    function Length(s): LongInt;
    Returns string length in characters.
    Usage :
    SCAR Code:
    Begin
      WriteLn(IntToStr(Length('the length of this is...')));
    end.
    Output : '24'

    procedure SetLength(var S, NewLength: LongInt);
    Sets the length of an integer to 'New Length'
    Usage :
    SCAR Code:
    SetLength(S, 5);
    for I := 0 to 4 do
    begin
      S[i] := 'H';
    end;
     Writeln(S);
    Output : 'HHHHH';

    Setlength is only used when you treat a string as an array of chars.

    function Padl(s: string; I: LongInt): string;
    'I' is how many spaces (this also includes length of text) to add before the String(s).
    Usage :
    SCAR Code:
    Begin
      WriteLn(Padl('abcd', 6));
    end.
    Output : '(Two Spaces) + abcd'

    function Padr(s: string; I: LongInt): string;
    'I' is how many spaces (this also includes length of text) to add after the String (s).
    Usage :
    SCAR Code:
    Begin
      WriteLn(Padr('abcd', 6) + 'll');
    end.
    OutPut : 'abcd (Two Spaces) ll'

    function Padz(s: string; I: LongInt): string;

    Adds '0''s before the string, same principle of Padr and Padl

    function Replicate(c: Char; I: LongInt): string;
    Writes Out a char (c) 'I' times.
    Usage :
    SCAR Code:
    Begin
      WriteLn(Replicate('a', 5));
    end.
    Output : 'aaaaa'
    ^ Please note the char can only be one string in length. ^

    function StringOfChar(c: Char; I: LongInt): string;
    Returns a string of c's with I length!

    function Left(Text: string; Count: Integer): string;

    Returns a part of the leftside of a string, the length is specified by Count (basically read : 'how much').
    Usage :
    SCAR Code:
    Begin
      WriteLn(Left('123456789', 6));
    end.
    Output : '123456'
    Please note that SCAR automatically reads text from the left hand side.

    function Right(Text: string; Count: Integer): string;
    Returns a part of the rightside of a string, the length is specified by Count (basically read :'how much from the end of the string').
    Usage :
    SCAR Code:
    Begin
      WriteLn(Right('123456789', 6));
    end.
    Output : '456789'
    ^ This reads the string the 'wrong - way round', this is pretty useful ^

    function Replace(Text, FindStr, ReplaceStr: string): string;
    Replaces all instances of FindStr in Text by ReplaceStr.
    Usage :
    SCAR Code:
    Begin
      WriteLn(Replace('hi bye hi bye', 'bye', 'hi'));
    end.
    Output : 'hi hi hi hi'

    function GetNumbers(Text: string): string;
    Returns all numbers found in a string.

    function GetLetters(Text: string): string;
    Returns all letters found in a string.

    function GetOthers(Text: string): string;
    Returns all non-numbers and non-letters in a string.

    function TrimNumbers(Text: string): string;
    Removes all numbers from a string.

    function TrimLetters(Text: string): string;
    Removes all letters from a string.

    function TrimOthers(Text: string): string;
    Removes all chars that are not numbers and not letters from a string.

    function Capitalize(S: string): string;
    Will capitalize strings.
    Usage :
    SCAR Code:
    Begin
      WriteLn(Capitalize('hello today i had a jam tart, i enjoyed it'));
    end.
    Output : 'Hello Today I Had A Jam Tart, I Enjoyed It'

    function InStrArr(Str: string; Arr: TStringArray; CaseSensitive: Boolean): Boolean;
    Returns true if the string Str is found in the TStringArray Arr, if the CaseSensitive Boolean is true it will compare the strings with casesensitivity, else without.
    My Summary : Will find the string (str) in the String Array (Arr) being exact or not exact (Case Sensitive).
    Usage :
    SCAR Code:
    Begin
     If InStrArr('hey', ['hey'], False) Then
       WriteLn('Found '#39'hey'#39' in the array, it rhymes');
    end.

    function PosEx(search, s: string; from: Integer): Integer;
    Returns the position of the substring in s searching forwards from from.
    SCAR Code:
    Begin
     If PosEx('lol', '12 lollol', 2) > 0 Then
       WriteLn('Found '#39'lol'#39' in the function');
    end.

    function LastPosEx(search, s: string; from: Integer): Integer;
    Returns the position of the substring in s searching backwards from from.
    Usage : Same as 'PosEx' but searches backwards.

    function LastPos(search, s: string): Integer;
    Returns the position of the substring in s searching backwards from the end of the string.
    Usage : Same as 'pos' but searches backwards

    function StartsWith(prefix, s: string): Boolean;
    Returns true if s starts with prefix.
    Usage :
    SCAR Code:
    Begin
      If StartsWith('s', 'snakes on a plain!!!') Then
        WriteLn('Omg it starts with an s');
    end.

    function EndsWith(suffix, s: string): Boolean;
    Returns true if s ends with suffix.
    Usage :
    SCAR Code:
    Begin
      If EndsWith('n', 'snakes on a plain') Then
        WriteLn('Omg it ends with an n');
    end.

    function TrimEx(delimiter, s: string): string;
    Trims the specified delimiter from the start and end of the string. Basically trims the string from the place specified.
    Usage :
    SCAR Code:
    Begin
      WriteLn(TrimEx('2', '2lol'));
    end.
    Output : 'lol'

    function RegexPos(Txt, Regex: string): Integer;
    Returns the position of the first found occurence of the regex.
    Usage :
    SCAR Code:
    Begin
    If RegexPos('lol', 'l') > 0 Then
      WriteLn('This is just like pos, but it finds a regular expression');
    end.
    Output : 'This is just like pos, but it finds a regular expression'

    function FindRegex(Txt, Regex: string): Integer;
    Returns the string found by the regex.
    Usage :
    SCAR Code:
    Begin
      WriteLn(FindRegex('hello', 'l'));
    end.
    Output : 'l' because it found 'l' in the regular expression (Regex).

    function ReplaceRegex(Txt, Regex, ReplaceStr: string): string;
    Replaces all occurences of the found regex by ReplaceStr.
    Usage :
    SCAR Code:
    Begin
      WriteLn(ReplaceRegex('hi lol hi', 'hi', 'lol'));
    end.
    Output : 'lol lol lol'

    function MD5(s: string): string;
    Converts a string to an MD5 hash. Used mainly for encryption.
    Geek definition : An MD5 hash is typically expressed as a 32 digit hexadecimal number. It uses an algorithm (systematic procedure) to encrypt the code.
    Usage :

    So for instance the word 'password' is '5f4dcc3b5aa765d61d8327deb882cf99'.

    So to use MD5 as encryption we must first write it to a file. We will use:

    function MD5FromFile(Filepath: string): string;
    Returns the MD5 hash value of a file.


    First we must write it to the file, example :
    SCAR Code:
    Var
      X : Integer;
      G : String;
    begin
     Try
       X := ReWriteFile(ScriptPath+'Guild X Min0r Proggies!.txt', False);
       G := MD5('password'); //This could be players[0].Pass
       WriteFileString(X, G);
     Except
       WriteLn('Error Occured');
     end;
    end.

    Then we can load it:

    SCAR Code:
    Var
      X : Integer;
      G : String;
    begin
     Try
       X := ReWriteFile(ScriptPath+'Guild X Min0r Proggies!.txt', False);
       G := MD5('password');
       WriteFileString(X, G);
     Except
       WriteLn('Error Occured');
     Finally
       G := MD5FromFile(ScriptPath+'Guild X Min0r Proggies!.txt'); //This could be players[0].Pass
       WriteLn(g);
     end;
    end.

    Simple



    III – End Note

    Hope you actually enjoyed this tutorial, what am I kidding, you guys are all nerds so you would have loved it!!! j/k.
    Really, if there’s a mistake you found or something I’ve done wrong then please tell me.
    Other than that Peace Out!!!!


    Credits:
    Yakman
    The Scar Noob
    Nielsie
    Sumilion
    Raymond
    EvilChicken


    Last edited by Daniel; 09-19-2012 at 01:06 PM.

  2. #2
    Join Date
    Oct 2007
    Location
    The deep web
    Posts
    2,496
    Mentioned
    1 Post(s)
    Quoted
    3 Post(s)

    Default

    super tut ftw.
    Did someone say GDK?

  3. #3
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default

    Thanks-for the quick reply. I spent ages on this

  4. #4
    Join Date
    Dec 2006
    Location
    Sweden
    Posts
    10,812
    Mentioned
    3 Post(s)
    Quoted
    16 Post(s)

    Default

    Nice work Should help those trying to make mass string scripts, for example: animating a "roflcopter", but in SCAR.


    Send SMS messages using Simba
    Please do not send me a PM asking for help; I will not be able to help you! Post in a relevant thread or make your own! And always remember to search first!

  5. #5
    Join Date
    May 2007
    Location
    Ohio
    Posts
    2,296
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    All i can say:
    "omfg"

  6. #6
    Join Date
    Mar 2007
    Location
    <3
    Posts
    2,683
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    DAMN!

    This was alot..
    Very nice tut!

  7. #7
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default

    Ha ha . Thanks for the comments.

  8. #8
    Join Date
    Jan 2007
    Posts
    8,876
    Mentioned
    123 Post(s)
    Quoted
    327 Post(s)

    Default

    SCAR Code:
    Var x : Integer;
    Begin
      SetLength(x, 80);
      WriteLn(IntToStr(x));
    end.
    This would not work at all... SetLength is mostly used in arrays
    I know you know it, but I just had to say it

  9. #9
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default

    Yeah thanks for that . I'll change it accordingly tommorrow, rep++

  10. #10
    Join Date
    Aug 2008
    Location
    Planet Earth.
    Posts
    53
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I like it!

    I'm sure they will come in useful.

    Tuts are so much easier than figuring out the SCAR MANUAL
    Learning: Italian!
    Code:
    <Jason2G's> I just sprayed WD-40 on my dog's nuts. He was sleeping. And now he can't get back to sleep ^_^

  11. #11
    Join Date
    Dec 2007
    Posts
    2,112
    Mentioned
    71 Post(s)
    Quoted
    580 Post(s)

    Default

    Ooo where did you get all those from i love the Padr, Padz And Padl

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

    Default

    procedure SetLength(var S, NewLength: LongInt);
    Sets the length of an integer to 'New Length'
    Usage :
    ScarScript: By Drunkenoldma

    Var x : Integer;
    Begin
    SetLength(x, 80);
    WriteLn(IntToStr(x));
    end.
    ^Incorrect.

    SetLength(S, 5);
    for I := 0 to 4 do
    begin
    S[I] := 'H';
    end;
    Writeln(S);

    Output : 'HHHHH';

    Setlength is only used when you treat a string as an array of chars.

    function StringOfChar(c: Char; I: LongInt): string;
    Just Like Replicate. Writes Out a char (c) 'I' times.
    ^ Actually, it returns a string of c's with I length!

    function Right(Text: string; Count: Integer): string;
    Returns a part of the rightside of a string, the length is specified by Count (basically read :'how much from the end of the string').
    Usage :
    ScarScript: By Drunkenoldma

    Begin
    WriteLn(Left('123456789', 6));
    end.


    Output : '456789'
    ^ This reads the string the 'wrong - way round', this is pretty useful ^
    ^Wrong function... Right

    Nice tut, thats the errors I found, don't want to be mean and misguide the noobs!
    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

  13. #13
    Join Date
    Jul 2007
    Location
    Norway.
    Posts
    1,938
    Mentioned
    3 Post(s)
    Quoted
    0 Post(s)

    Default

    Youknowwhat naum, I skimmed over it and it looked really much nicer than what I expected. I don'treallyknowwhy, but the title made it sound so stupid and lowered my expectations.

    If you wouldn't have had the tut cup already, I would've nominated you.
    Good job!

    :rep+:


    E: Must spread some rep before giving it to nauman again =____=

  14. #14
    Join Date
    Dec 2006
    Location
    SC
    Posts
    692
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    This is a bit more than a list . Very nice job.

  15. #15
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default

    Thanks Nava2 I fixed the errors! Thanks EvilChicken and WhoCares (the tut master) . Thanks for all the comments aswell

    Updated the tutorial a bit.

  16. #16
    Join Date
    Dec 2006
    Location
    Program TEXAS home of AUTOERS
    Posts
    7,934
    Mentioned
    26 Post(s)
    Quoted
    237 Post(s)

    Default

    woah wow, didnt know there is so much of string.

    gj

    Rep

  17. #17
    Join Date
    Dec 2007
    Location
    Michigan, USA
    Posts
    280
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    great tut man <33
    Kindof Inactive...

  18. #18
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default

    Thank-you very much

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. SCAR command list?
    By MetalancA in forum OSR Help
    Replies: 10
    Last Post: 06-08-2008, 10:09 AM
  2. List of Srl or SCar commands
    By looneytoon in forum OSR Help
    Replies: 7
    Last Post: 01-08-2007, 01:01 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
  •