Jump to content

stringsort ?


rakudave
 Share

Recommended Posts

edit... I was thinking of something else....

Edited by SpookMeister

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

is it always going to be numbers?

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

#include <Array.au3>
$s_test = "869475231"
$a_test = StringSplit($s_test,"")
_ArrayDelete($a_test,0)
_ArraySort($a_test)
;~ _ArrayDisplay($a_test,"test")
$s_test = ""
for $x = 0 To UBound($a_test) - 1
    $s_test = $s_test & $a_test[$x]
Next
MsgBox(0,"sorted",$s_test)

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

You might put the string into an array character by character, then sort the array with _ArraySort then put it back into a string.

Edit... like gafrost just sugested :P

Edited by SpookMeister

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

i hope i don't bore you but i found nothing in the helpfile or forum...

i've got a string like "869475231" and i'd like to sort it, like "123456789"

=> how do i do this ???

thx

easiest way would probably be:

#include<array.au3>
Dim $blah
$string = "987654321"
$blah = StringSplit($string,"")
_ArraySort($blah,0,1)

$tmp = ""
For $x = 1 to $blah[0]
    $tmp = $tmp & $blah[$x]
Next
MsgBox(0,"Output",$tmp)

should be able to use _ArrayToString() to convert it back, but it never works for me so i just do it with my own loop

***edit** looks like gary beat me to it

Edited by cameronsdad
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...