Raised This Month: $51 Target: $400
 12% 

Sort a string in alphabetical order


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Facksy
Senior Member
Join Date: Apr 2017
Location: +2+2
Old 05-05-2018 , 09:05   Sort a string in alphabetical order
Reply With Quote #1

hey guys, is it possible to sort a string in alphabetical order?
PHP Code:
{
    
char[] sString "mrbaft";
    
//Funtion to sort in alphabetical order
    //so sString will be sString = "abfmrt"

__________________
My Steam I take private requests if related with TF2
My Plugins
Facksy is offline
sdz
Senior Member
Join Date: Feb 2012
Old 05-05-2018 , 14:12   Re: Sort a string in alphabetical order
Reply With Quote #2

use this StrAlphabetize thing i wrote/scrapped from some C snippet

PHP Code:
#include <sourcemod>

public void OnPluginStart()
{
    
RegConsoleCmd("sm_sort"Command_Sort"sort");
}

public 
Action Command_Sort(int clientint argc)
{
    
char arg[128];
    
GetCmdArgString(argsizeof(arg));

    
StrAlphabetize(argarg);
    
PrintToChat(clientarg);

    return 
Plugin_Handled;
}

//Returns bytes written or something
public int StrAlphabetize(const char[] sourcechar[] ret)
{
    
int len strlen(source);

    
char letter;
    
int count[26], poscursor;

    for(
int i 0leni++)
    {
        
letter source[i] - 'a';
        
count[letter]++;
    }

    
cursor 0;

    for(
letter 'a'letter <= 'z'letter++)
    {
        
pos letter 'a';
        for(
int i 0count[pos]; i++)
        {
            
ret[cursor] = letter;
            
cursor++;
        }
    }

    
ret[cursor] = '\0';
    return 
cursor;


Last edited by sdz; 05-05-2018 at 14:14.
sdz is offline
Reply



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

Forum Jump


All times are GMT -4. The time now is 20:32.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode