PDA

View Full Version : A List Of All String Functions in SCAR ~ Naum



Naum
11-27-2008, 05:31 PM
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 :
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 :
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

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 :
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:
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 :
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 :
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 :
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 :

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 :
Begin
WriteLn(Uppercase('hey guyz'));
end.
OutPut : 'HEY GUYZ'

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

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


function Length(s): LongInt;
Returns string length in characters.
Usage :
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 :

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 :
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 :
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 :
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 :
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 :
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 :
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 :
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 :
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.
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 :
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 :
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 :
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 :
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 :
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 :
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 :
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:

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

:spongebob: :spongebob: :spongebob: :spongebob: :spongebob: :spongebob: :spongebob: :spongebob: :spongebob:

jakeyboy29
11-27-2008, 05:33 PM
super tut ftw.

Naum
11-27-2008, 05:34 PM
Thanks-for the quick reply. I spent ages on this :)

Harry
11-27-2008, 05:48 PM
Nice work :) Should help those trying to make mass string scripts, for example: animating a "roflcopter", but in SCAR.

Timer
11-27-2008, 05:49 PM
All i can say:
"omfg"

Naike
11-27-2008, 05:49 PM
DAMN!

This was alot..
Very nice tut!

Naum
11-27-2008, 07:34 PM
Ha ha :). Thanks for the comments.

Zyt3x
11-27-2008, 08:03 PM
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 :D

Naum
11-27-2008, 08:13 PM
Yeah thanks for that :). I'll change it accordingly tommorrow, rep++

Enchanted
11-27-2008, 08:21 PM
I like it!

I'm sure they will come in useful.

Tuts are so much easier than figuring out the SCAR MANUAL :)

Kasi
11-27-2008, 09:42 PM
Ooo where did you get all those from i love the Padr, Padz And Padl

Nava2
11-28-2008, 12:36 AM
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! :)

EvilChicken!
11-28-2008, 12:39 AM
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 =____=

WhoCares357
11-28-2008, 01:21 AM
This is a bit more than a list :D. Very nice job.

Naum
11-30-2008, 12:44 PM
Thanks Nava2 I fixed the errors! Thanks EvilChicken and WhoCares (the tut master) :p. Thanks for all the comments aswell

Updated the tutorial a bit.

P1nky
12-01-2008, 04:06 AM
woah wow, didnt know there is so much of string.

gj :)

Rep

mikevskater
12-02-2008, 01:22 PM
great tut man <33
:spot:

Naum
12-15-2008, 09:39 PM
Thank-you very much :)