[Include] [INC] strlib v1.3 - Simple string modification (Update: 21/10/09)
#1

strlib - v1.3

Missed PHP's excellent string modification functions? Yeah, but that was because it was easy. I decided to create a string include that is stand alone - each function works in or out of the include - no dependencies apart from the core supplied files. But why? Because I can, and I wanted it. I wanted to be able to effectively cut strings up into pieces, remove stupid white space from lines in files, remove certain characters from certain words for a certain effect, or even replace whole words if you want to. You can do what ever you want, within reason, with this.

Function tests prove efficiency, albeit outdated efficiency!

Function list
Remember that this is the function list that you need to know, the full documentation is in the source code.
pawn Code:
/*
    str_replace:
        Case sensitive string replace

    Arguments:
        sSearch[]    String to search for
        sReplace[]   String to replace with
        sSubject[]   Original string
        (op) &iCount  How many times 'sSearch' has been replaced.

    Returns:
        Replaced string.
*/

native str_replace(sSearch[], sReplace[], const sSubject[], &iCount = 0)
pawn Code:
/*
    str_ireplace:
        Case insensitive string replace

    Arguments:
        sSearch[]    String to search for
        sReplace[]   String to replace with
        sSubject[]   Original string
        (op) &iCount  How many times 'sSearch' has been replaced.

    Returns:
        Replaced string.
*/

native str_ireplace(sSearch[], sReplace[], const sSubject[], &iCount = 0)
pawn Code:
/*
    str_pad:
        Pad a string with characters until the defined amount.

    Arguments:
        sSource[]     String input to pad.
        iPadLength    Pad to amount. If less than sSource, sSource is returned.
        (op) cPadChar  Character to use as padding.

    Returns:
        Padded string.
*/

native str_pad(const sSource[], iPadLength, cPadChar = ' ')
pawn Code:
/*
    str_repeat:
        Repeats a string 'iMultiplier' times.

    Arguments:
        sSource[]   String to be repeated
        iMultiplier Amount of times to be repeated

    Returns:
        Repeated string.
*/

native str_repeat(const sSource[], iMultiplier)
pawn Code:
/*
    str_rot13:
        Rotates alphabetical characters 13 characters along.

    Arguments:
        sSource[]   String to be rotated

    Returns:
        Rotated string.
*/

native str_rot13(const sSource[])
pawn Code:
/*
    strtr:
        Removes 'sRemove' from the string and replaces
        that character from 'sReplace'.

    Arguments:
        sSource[]   String to be transformed
        sRemove[]  Characters to be removed (must be in same order as below!)
        sReplace[]  Characters to be replaced (must be in same order as above!)

    Returns:
        Trimmed string.
*/

native strtr(const sSource[], sRemove[], sReplace[])
pawn Code:
/*
    substr:
        Gets a substring from a string.

    Arguments:
        sSource[]   String to be substring'd.
        iStart    Position for the start of substring.
        iLength    Position for the end of substring.
                (if negative, cells away from end)

    Returns:
        Substring.
*/

native substr(const sSource[], iStart, iLength = sizeof(sSource))
pawn Code:
/*
    trim:
        Removes whitespace, tabs, and new lines
        from the beginning and end of 'sSource'.

    Arguments:
        sSource[]   String to be trimmed

    Returns:
        Trimmed string.
*/

native trim(const sSource[])
pawn Code:
/*
    rtrim:
        Removes whitespace, tabs, and new lines
        from the end of 'sSource'.

    Arguments:
        sSource[]   String to be trimmed

    Returns:
        Trimmed string.
*/

native rtrim(const sSource[])
pawn Code:
/*
    ltrim:
        Removes whitespace, tabs, and new lines
        from the beginning of 'sSource'.

    Arguments:
        sSource[]   String to be trimmed

    Returns:
        Trimmed string.
*/

native ltrim(const sSource[])
pawn Code:
/*
    implode:
        Returns a string where the array has been stuck back together
        again.

    Arguments:
        aPieces[][]  The array to glue back together.
        sGlue     The string to use as the glue.

    Returns:
        The imploded string.
*/

native implode(const aPieces[][], const sGlue[] = " ")
pawn Code:
/*
    explode:
        Creates an array of values from 'sSource', where only the exact amount of
        values matching sizeof(aExplode) are returned.

    Arguments:
        aExplode[][] The exploded array
        sSource[]   Source string.
        sDelimiter  The string to use as the delimiter.

    Returns:
        Returns -1 on failure, otherwise success.
*/

native explode(aExplode[][], sSource[], sDelimiter[] = " ")
pawn Code:
/*
    explodea:
        Creates an array of values from 'sSource', where any overrun is stored in
        the final node.

    Arguments:
        aExplode[][] The exploded array
        sSource[]   Source string.
        sDelimiter  The string to use as the delimiter.

    Returns:
        Returns -1 on failure, otherwise success.
*/

native explodea(aExplode[][], sSource[], sDelimiter[] = " ")
pawn Code:
/*
    str_in_array:
        Checks if a string matches any of the strings in the array.

    Arguments:
        sNeedle[]   String that is being matched.
        aHaystack[][] Array with strings to be searched,

    Returns:
        Returns true on a match.
*/

native str_in_array(sNeedle[], aHaystack[][])
Download: http://files.typefish.co.uk/sa-mp/strlib.inc
-> No mirrors thanks.

Fancy documentation: http://docs.typefish.co.uk/samp/pawn/strlib/

Any problems, post in the topic. See ya!
Reply


Messages In This Thread
[INC] strlib v1.3 - Simple string modification (Update: 21/10/09) - by Westie - 09.07.2009, 02:01
Re: [INC] strlib - Simple string modification - by Chaprnks - 09.07.2009, 02:27
Re: [INC] strlib - Simple string modification - by NeRoSiS - 09.07.2009, 07:26
Re: [INC] strlib - Simple string modification - by Westie - 09.07.2009, 14:51
Re: [INC] strlib - Simple string modification - by Correlli - 09.07.2009, 15:04
Re: [INC] strlib - Simple string modification - by GTA_Rules - 10.07.2009, 19:46
Re: [INC] strlib - Simple string modification - by yezizhu - 19.07.2009, 10:53
Re: [INC] strlib - Simple string modification - by James_Alex - 19.07.2009, 19:06
Re: [INC] strlib - Simple string modification - by Westie - 27.07.2009, 00:06
Re: [INC] strlib - Simple string modification (Update: 27/07/09) - by GTA_Rules - 27.07.2009, 15:29
Re: [INC] strlib - Simple string modification (Update: 27/07/09) - by Marcel - 27.07.2009, 16:21
Re: [INC] strlib - Simple string modification (Update: 27/07/09) - by Westie - 27.07.2009, 17:36
Re: [INC] strlib - Simple string modification (Update: 27/07/09) - by Brendan_Thomson - 18.08.2009, 12:28
Re: [INC] strlib - Simple string modification (Update: 27/07/09) - by Dabombber - 21.08.2009, 05:40
Re: [INC] strlib - Simple string modification (Update: 27/07/09) - by nuriel8833 - 21.08.2009, 07:29
Re: [INC] strlib - Simple string modification (Update: 27/07/09) - by Brendan_Thomson - 21.08.2009, 09:06
Re: [INC] strlib - Simple string modification (Update: 27/07/09) - by Brendan_Thomson - 05.09.2009, 15:35
Re: [INC] strlib - Simple string modification (Update: 27/07/09) - by Westie - 13.09.2009, 10:09
Re: [INC] strlib - Simple string modification (Update: 27/07/09) - by Calgon - 13.09.2009, 10:15
Re: [INC] strlib v1.3 - Simple string modification (Update: 21/10/09) - by Westie - 21.10.2009, 21:42
Re: [INC] strlib v1.3 - Simple string modification (Update: 21/10/09) - by MenaceX^ - 21.10.2009, 21:51
Re: [INC] strlib v1.3 - Simple string modification (Update: 21/10/09) - by Kyeno - 21.12.2009, 11:34
Re: [INC] strlib v1.3 - Simple string modification (Update: 21/10/09) - by _Gangster_ - 21.12.2009, 11:49
Re: [INC] strlib v1.3 - Simple string modification (Update: 21/10/09) - by GTA_Rules - 22.12.2009, 09:54
Re: [INC] strlib v1.3 - Simple string modification (Update: 21/10/09) - by GreenHammy - 03.01.2010, 09:20
Re: [INC] strlib v1.3 - Simple string modification (Update: 21/10/09) - by Puffmac - 09.01.2010, 19:06
Re: [INC] strlib v1.3 - Simple string modification (Update: 21/10/09) - by mario713 - 09.02.2010, 00:23
Re: [INC] strlib v1.3 - Simple string modification (Update: 21/10/09) - by Calgon - 09.02.2010, 01:34
Re: [INC] strlib v1.3 - Simple string modification (Update: 21/10/09) - by Westie - 09.02.2010, 15:33
AW: [INC] strlib v1.3 - Simple string modification (Update: 21/10/09) - by Meta - 16.11.2010, 21:08
Re: [INC] strlib v1.3 - Simple string modification (Update: 21/10/09) - by Grim_ - 16.11.2010, 21:10
Re: [INC] strlib v1.3 - Simple string modification (Update: 21/10/09) - by Luka P. - 16.11.2010, 21:41
Re: [INC] strlib v1.3 - Simple string modification (Update: 21/10/09) - by Donya - 06.04.2011, 17:53
Re: [INC] strlib v1.3 - Simple string modification (Update: 21/10/09) - by Minokon - 06.04.2011, 17:59
Re: [INC] strlib v1.3 - Simple string modification (Update: 21/10/09) - by Ironboy - 19.04.2011, 05:00
Re: [INC] strlib v1.3 - Simple string modification (Update: 21/10/09) - by Westie - 19.06.2011, 18:24
Re: [INC] strlib v1.3 - Simple string modification (Update: 21/10/09) - by clavador - 20.03.2012, 20:54
Re: [INC] strlib v1.3 - Simple string modification (Update: 21/10/09) - by ikkentim - 10.04.2012, 18:51
Re: [INC] strlib v1.3 - Simple string modification (Update: 21/10/09) - by QTSwift - 10.09.2013, 06:17
Re: [INC] strlib v1.3 - Simple string modification (Update: 21/10/09) - by Emre__ - 19.08.2014, 01:40
Re: [INC] strlib v1.3 - Simple string modification (Update: 21/10/09) - by ball - 16.05.2018, 12:39
Re: [INC] strlib v1.3 - Simple string modification (Update: 21/10/09) - by Yousha - 16.05.2018, 12:46
Re: [INC] strlib v1.3 - Simple string modification (Update: 21/10/09) - by Kar - 16.05.2018, 14:16
Re: [INC] strlib v1.3 - Simple string modification (Update: 21/10/09) - by Yousha - 17.05.2018, 17:02
Re: [INC] strlib v1.3 - Simple string modification (Update: 21/10/09) - by Yousha - 19.05.2018, 08:18

Forum Jump:


Users browsing this thread: 1 Guest(s)