[Include] Recreational Mathematics and String Add-On Library
#1

Add - On Library



This is an add-on library include for pawn coding, I have seen that pawn lacks few string and recreational mathematical library functions, which may or may not be important ,but as per my way of thinking, they are a bit important.
This include is just an add-on, if you are using other string libraries (westie's, oscar broman) instead of pawn's default/user or sa-mp team created library, I would like to suggest you to use this add-on along with them/it, as this add-on gives scripters freedom of various string manipulating and recreational mathematical functions, this include is mainly for string manipulation. If you have any suggestions ,please post in this thread.
Important: v1.2 Update, please go through the functions list once again.


Function Lists:


ToPalindrome(input[]): Converts a string to a palindrome string.

IsPalindrome(input[]): Checks whether a string is palindrome or not.

IsArmstrong(value): Recreational mathematical function.Useful for reaction tests. Checks whether the number is armstrong or not.WikipediaReturns boolean type.

IsNeon(value):Checks for Neon number example: 9 (is a neon number) = 9*9=81 , 8+1=9. These type of numbers are known as neon numbers.Returns boolean type.

IsPerfect(value) : WikipediaReturns boolean type.

IsEvenOrOdd(value): Checks if the number given is even or odd.Returns boolean type.

IsPrime(value): Checks for prime numbers.Returns boolean type.

IsMagic(value): Magic number example: 55 (is a magic number) = 5+5=10, 1+0=1.
289(is a magic number) = 2+8+9=19, 1+9=10, 1+0=1
Returns boolean type.


MaxDigit(value): Returns the maximum digit present in a sequence of a number. Example: 46789 ,Max=9
Returns boolean type.


MinDigit(value): Returns the minimum digit present in a sequence of a number. Example: 46789 ,Min=4

FirstIndexOf(string[],character[]): Returns the first index of a character present in a string.

LastIndexOf(string[],character[]): Returns the last index of a character present in a string.

Truncate(Float:value): Removes the fractional part of a floating data type. Example: 5.98 ,Return 5

IsSpace(character[]): Checks whether a character is a space or not.Returns boolean type.

IsUnderscore(character[]): Checks whether a character is an underscore or not.Returns boolean type.

IsDigit(character[]): Checks whether a character is a digit or not.Returns boolean type.

IsLetter(character[]): Checks whether a character is a letter or not.Returns boolean type.

IsUpperCase(character[]): Checks whether a character is an uppercase letter or not.Returns boolean type.

IsLowerCase(character[]): Checks whether a character is an lowercase letter or not.Returns boolean type.

Reverse(string[]): Reverses a given string.

Compare(string1[],string2[]): Compare lengths of two strings

Retrurns 0 If both string's length are same.
Returns 1 If length of string1 is greater than string2
Returns -1 If length of string2 is greater than string1


CharAt(string[],index): Returns a character present in the given index of a string.

ReplaceChar(string[],character[],replacewith[]): Replace a character in a given string.

Example: ReplaceChar("codectile","c","z");
Output: "zodeztile"


IsSpecial(character[]): Returns 1 if a character is neither a digit or a letter.Returns boolean type.

Substring(string[],firstindex,lastindex): Substrings the string.

Example: Substring("codectile",2,5)
Returns "dect"




Concat(string1[],string2[]): Concatenates two strings.

Example: Concat("codec","tile");
Returns: "codectile"



ExtStr(string[]): Extract string type characters

Example: ExtStr("c874o10d74e1c9t0i14l98e");
Returns : "codectile"



Frequency(string[],character[]): Returns the frequency of a character present in a string.

Example: Frequency("codectile","c");
Returns: 2




Equals(string1[],string2[]): Checks whether two strings are similar or not.Note: Case Sensitive

Example: Equals("codec","tile");
Returns: false

Example: Equals("codectile","codectile");
Returns: true



DigitFreq(value,digit): Returns the frequency of a digit in a sequence of numbers

Example: Digit(46667,6);
Returns: 3




ToPositive(Float:value): Converts a negative integer to a positive integer.



ToNegitive(Float:value): Converts a positive integer to a negative integer.






Download:

Mediafire v1.2 Update
SolidFiles v1.2 Update




Credits:

Y_Less : For suggesting functions name for MaxDigit/MinDigit

Sa-Mp Team: For samp client.

And God : For world.
Reply
#2

Nice One. I will add it to my test Gamemode. Keep it up man. Good Luck.
Reply
#3

Substring function added and made some of the functions more accurate and precise.

Version 1.1.
Reply
#4

For CharAt it's useless, just do String[Index] ... Imagine doing CharAt in a loop, will make your code so inefficient.

You can also do:

#define CharAt(%0,%1) ((%1 < 0 || %1 > sizeof(%0)) ? '\0' : %0[%1])
#define CharAt_(%0,%1) CharAt(%0,%1 - 1) // To start at an index of 1.

A lot of other functions can be turned into definition 'macros' as well for efficiency reasons.
This is useful regardless but you can improve it.

Edit:
Sorry for criticism, I notice you just joined, please look-up the user Y_Less, he has a lot of good tutorials you can follow and read apon.
https://sampforum.blast.hk/showthread.php?tid=166680
Reply
#5

Pastebin your work too, please.
Reply
#6

@SkittlesAreFalling: Give me some time to learn macro defining, I am not too familiar with C++/C coding.

@Kar: Why pastebin ? , if you can directly download the add-on library and include it in your script.
Reply
#7

Quote:
Originally Posted by codectile
View Post
@SkittlesAreFalling: Give me some time to learn macro defining, I am not too familiar with C++/C coding.

@Kar: Why pastebin ? , if you can directly download the add-on library and include it in your script.
Yes, Pastebin it. It's easy-to-browse.
Reply
#8

I will, next time for next version maybe.
Reply
#9

Version 1.2 Updated.
Reply
#10

I still see no pastebin
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)