SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 09/07/2009, 03:01 AM   #1
Westie
Gangsta
 
Westie's Avatar
 
Join Date: Jul 2009
Posts: 863
Reputation: 63
Default [INC] strlib v1.3 - Simple string modification (Update: 21/10/09)

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

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)

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 = ' ')

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)

Code:
/*
    str_rot13:
        Rotates alphabetical characters 13 characters along.

    Arguments:
        sSource[]   String to be rotated

    Returns:
        Rotated string.
*/
native str_rot13(const sSource[])

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[])

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

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[])

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[])

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[])

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[] = " ")

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[] = " ")

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[] = " ")

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!

Last edited by Westie; 21/12/2010 at 06:55 PM.
Westie is offline   Reply With Quote
Old 09/07/2009, 03:27 AM   #2
Chaprnks
Gangsta
 
Chaprnks's Avatar
 
Join Date: Sep 2007
Location: Soviet America
Posts: 676
Reputation: 41
Default Re: [INC] strlib - Simple string modification

Hmm, I will definitely make use of this in the future.
__________________
Chaprnks is offline   Reply With Quote
Old 09/07/2009, 08:26 AM   #3
NeRoSiS
Gangsta
 
Join Date: Feb 2008
Posts: 595
Reputation: 3
Default Re: [INC] strlib - Simple string modification

This is extremely useful, nice job!
NeRoSiS is offline   Reply With Quote
Old 09/07/2009, 03:51 PM   #4
Westie
Gangsta
 
Westie's Avatar
 
Join Date: Jul 2009
Posts: 863
Reputation: 63
Default Re: [INC] strlib - Simple string modification

Alright, I have modified strtr so that you are able to remove characters all together. Check the first post for details.
Westie is offline   Reply With Quote
Old 09/07/2009, 04:04 PM   #5
Correlli
Godfather
 
Correlli's Avatar
 
Join Date: May 2009
Location: Slovenia
Posts: 7,173
Reputation: 360
Default Re: [INC] strlib - Simple string modification

Good work.
Correlli is offline   Reply With Quote
Old 10/07/2009, 08:46 PM   #6
GTA_Rules
Huge Clucker
 
Join Date: Aug 2008
Posts: 456
Reputation: 3
Default Re: [INC] strlib - Simple string modification

Nice work Westie
GTA_Rules is offline   Reply With Quote
Old 19/07/2009, 11:53 AM   #7
yezizhu
Gangsta
 
yezizhu's Avatar
 
Join Date: Nov 2007
Location: Shenzhen,China
Posts: 653
Reputation: 2
Default Re: [INC] strlib - Simple string modification

Very useful, good job!
yezizhu is offline   Reply With Quote
Old 19/07/2009, 08:06 PM   #8
James_Alex
Gangsta
 
Join Date: Dec 2008
Posts: 597
Reputation: 0
Default Re: [INC] strlib - Simple string modification

cool
James_Alex is offline   Reply With Quote
Old 27/07/2009, 01:06 AM   #9
Westie
Gangsta
 
Westie's Avatar
 
Join Date: Jul 2009
Posts: 863
Reputation: 63
Default Re: [INC] strlib - Simple string modification

Updated, added functions for exploding strings! Kaboom.
Westie is offline   Reply With Quote
Old 27/07/2009, 04:29 PM   #10
GTA_Rules
Huge Clucker
 
Join Date: Aug 2008
Posts: 456
Reputation: 3
Default Re: [INC] strlib - Simple string modification (Update: 27/07/09)

Sorry I don't get what explode does, could you explain me? If it does what I think it does, I could use it :+
GTA_Rules is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Payday Modification SeQualX Help Archive 3 12/07/2010 04:31 PM
[FilterScript] [FS] Drift3r's Simple Vehicle Spawner *0.1b Update* ray8995 Filterscripts 20 15/05/2010 02:22 PM
[Modification] | SAMP Gui - Simple modification of samp Interface (InGame) LuxurioN™ Everything and Nothing 21 15/03/2010 02:55 PM
MOVED: SA-MP Server (EXE) modification - Do you like it? Woet Help Archive 0 02/11/2009 07:43 AM
GTA modification compatibility with SA-MP Lordician General 1 19/08/2009 08:03 PM


All times are GMT. The time now is 06:24 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.