Difference between revisions of "George Procedures : Basic"
From TVPaintWiki
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
<<<[[George]]<<<[[George Command Reference]] | <<<[[George]]<<<[[George Command Reference]] | ||
+ | |||
These are the functions from the include script basic.grg | These are the functions from the include script basic.grg | ||
+ | // If you want to include advanced ass well you can collect all the procedures in one grg file or put a inluce statement in the Basic.grg like this and only Include basic.grg in you main script. You cannot include 2 text files with Procedures in your script. | ||
+ | #INCLUDE "advanced.grg" | ||
== Find(string,car,start) == | == Find(string,car,start) == |
Latest revision as of 09:53, 11 June 2014
<<<George<<<George Command Reference
These are the functions from the include script basic.grg
// If you want to include advanced ass well you can collect all the procedures in one grg file or put a inluce statement in the Basic.grg like this and only Include basic.grg in you main script. You cannot include 2 text files with Procedures in your script.
#INCLUDE "advanced.grg"
Contents
Find(string,car,start)
//------------------------------------------ // // Find // // Function: find a character into a string // from a specified start position // // Call: Find(string,car,start) // // Arguments: // string = characters string // car = character to look for // start = start position in string // // Return: position of character // 0 if character does not exist // into string // -1 if invalid position // (negative, null or higher // than string length) // //------------------------------------------ FUNCTION Find(string,car,start) LOCAL i size i = start size = LEN(string) IF ((start <= 0) || (start > size) || (CMP(car,"") == 1)) RETURN -1 END DO IF (CMP(CHAR(string,i),car) == 1) RETURN i END UNTIL ((i=i+1) > size) RETURN 0 END
FirstPos(string,car)
//------------------------------------------ // // FirstPos // // Function: find first occurence of a // character into a string // // Call: FirstPos(string,car) // // Arguments: // string = characters string // car = character to look for // // Return: position of character // or 0 id character does not // exist into string. // //------------------------------------------ FUNCTION FirstPos(string,car) RETURN Find(string,car,1) END
LastPos(string,car)
//------------------------------------------ // // LastPos // // Function: find last occurence of a // character into a string // // Call: LastPos(string,car) // // Arguments: // string = characters string // car = character to look for // // Return: position of character // or 0 if character does not // exist into string. // //------------------------------------------ FUNCTION LastPos(string,car) LOCAL loop myChar pos = LEN(string) loop = 1 WHILE loop myChar = CHAR(string,pos) IF CMP(myChar,car) == 1 loop =0 ELSE pos = pos-1 END IF pos<1 loop=0 END END RETURN pos END
FindString(string,search,start)
//------------------------------------------ // // FindString // // Function: find a substring into a string // from a specified start position // // Call: FindString(string,search,start) // // Arguments: // string = characters string // search = substring to look for // start = start position in string // // Return: start position of substring // 0 if substring does not exist // into string // -1 if invalid start position // (negative, null or higher // than string length) or if // substring is empty // //------------------------------------------ FUNCTION FindString(string,search,start) LOCAL found j pos lastpos lstr lsrch found = 0 lastpos = start lstr = LEN(string) lsrch = LEN(search) IF (CMP(search,"") == 1) RETURN -1 END WHILE ((pos = Find(string,CHAR(search,1),lastpos)) > 0) j = 1 found = 1 IF (j == lsrch) RETURN pos END WHILE ((j < lsrch) && (found == 1)) IF ((pos+j) > lstr) RETURN 0 ELSE IF (CMP(CHAR(search,j+1),CHAR(string,pos+j)) == 0) lastpos = pos+j found = 0 END END j = j+1 END IF (found == 1) RETURN pos END END RETURN pos END
LeftString(string,number)
//------------------------------------------ // // LeftString // // Function: extract a substring beginning // at the start of a string // // Call: LeftString(string,number) // // Arguments: // string = characters string // number = number of character to // extract from string // // Return: result substring // or 0 if number is negative // or null. // //------------------------------------------ FUNCTION LeftString(string,number) LOCAL size size = LEN(string) IF (number > 0) IF (number > size) number = size END RETURN CUT(string,1,number) END RETURN 0 END
RightString(string,number)
//------------------------------------------ // // RightString // // Function: extract a substring ending // at the end of a string // // Call: RightString(string,number) // // Arguments: // string = characters string // number = number of character to // extract from string // // Return: result substring // or 0 if number is negative // or null. // //------------------------------------------ FUNCTION RightString(string,number) LOCAL size size = LEN(string) IF (number > 0) IF (number > size) number = size END RETURN CUT(string,size-number+1,size) END RETURN 0 END
MidString(string,first,size)
//------------------------------------------ // // MidString // // Function: extract a substring from a // string // // Call: MidString(string,first,size) // // Arguments: // string = characters string // first = start position in string // cha�ne // size = number of characters // // Return: result substring // or 0 if number or first are // negatives or null. // //------------------------------------------ FUNCTION MidString(string,first,size) LOCAL ln ln = LEN(string) IF ((first > 0) && (size > 0)) IF ((first+size-1) > ln) size = ln-first+1 END RETURN CUT(string,first,first+size-1) END RETURN 0 END
InsertAtPos(string,insert,pos)
//------------------------------------------ // // InsertAtPos // // Function: insert a string in another // string at a specified position // // Call: InsertAtPos(string,insert,pos) // // Arguments: // string = characters string // insert = string to insert // pos = start position for insertion // // Return: result string after insertion // or 0 if start position is // invalid (negative, null or // higher than string length) // //------------------------------------------ FUNCTION InsertAtPos(string,insert,pos) LOCAL workstr str1 size size = LEN(string) IF ((pos < 0) || (pos > size)) RETURN 0 END IF (pos == 0) RETURN insert""string END IF (pos == size) RETURN string""insert END workstr = CUT(string,1,pos) IF (pos < size) str1 = CUT(string,pos+1,size) RETURN workstr""insert""str1 ELSE RETURN workstr""insert END END