Sign in to follow this  
Followers 0
usera

letters and word

6 posts in this topic

Greeting,

I am looking for a way to sort word which built by 4 letters

for example:

abac ---> I want the result is aabc

azay ----> I want the result is aayz

bxcy ----> I want the result is bcxy

which are sorted from a to z

Thanks

usera

Share this post


Link to post
Share on other sites



Take a look at this topic:

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Check this out

#include <Array.au3>
$String = "abac " & "azay " & "bxcy" ;Note that here the delimiter is space for the words.

MsgBox(64, "Sorted Words", Sort_Words($String, 1, " "))



Func Sort_Words($String, $iDescending, $sDelimiter = -1)
If $String = "" Then Return SetError(1, 0, 0)
If $sDelimiter = -1 Then Return SetError(2, 0, 0)

;Split up into words
$aWords = StringSplit($String, $sDelimiter, 3)
If @error Then Return SetError(3, 0, 0)

Local $Temp
For $i = 0 To UBound($aWords) - 1
$Temp = StringRegExp($aWords[$i], "(?s).", 3)
_ArraySort($Temp, $iDescending)
$aWords[$i] = _ArrayToString($Temp, "")
Next

Return _ArrayToString($aWords, $sDelimiter)
EndFunc ;==>Sort_Words

Orelse

#include <Array.au3>

;Orelse pass the Words Directly
MsgBox ( 64, "Ascending", Sort_Word("abac", 0))
MsgBox ( 64, "Descending", Sort_Word("azay", 1))
MsgBox ( 64, "Ascending", Sort_Word("bxcy", 0))

Func Sort_Word($S_Word, $iDescending)

$aWord = StringRegExp($S_Word, "(?s).", 3)
_ArraySort($aWord, $iDescending)
Return _ArrayToString($aWord, "")

EndFunc   ;==>Sort_Word
This is only for ASCII strings with case-insensitivity

Regards :)

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

Take a look at this topic:

thanks, that is help

Share this post


Link to post
Share on other sites

Check this out

#include <Array.au3>
$String = "abac " & "azay " & "bxcy" ;Note that here the delimiter is space for the words.

MsgBox(64, "Sorted Words", Sort_Words($String, 1, " "))



Func Sort_Words($String, $iDescending, $sDelimiter = -1)
If $String = "" Then Return SetError(1, 0, 0)
If $sDelimiter = -1 Then Return SetError(2, 0, 0)

;Split up into words
$aWords = StringSplit($String, $sDelimiter, 3)
If @error Then Return SetError(3, 0, 0)

Local $Temp
For $i = 0 To UBound($aWords) - 1
$Temp = StringRegExp($aWords[$i], "(?s).", 3)
_ArraySort($Temp, $iDescending)
$aWords[$i] = _ArrayToString($Temp, "")
Next

Return _ArrayToString($aWords, $sDelimiter)
EndFunc ;==>Sort_Words

Orelse

#include <Array.au3>

;Orelse pass the Words Directly
MsgBox ( 64, "Ascending", Sort_Word("abac", 0))
MsgBox ( 64, "Descending", Sort_Word("azay", 1))
MsgBox ( 64, "Ascending", Sort_Word("bxcy", 0))

Func Sort_Word($S_Word, $iDescending)

$aWord = StringRegExp($S_Word, "(?s).", 3)
_ArraySort($aWord, $iDescending)
Return _ArrayToString($aWord, "")

EndFunc ;==>Sort_Word
This is only for ASCII strings with case-insensitivity

Regards :)

thanks, Great Code

Share this post


Link to post
Share on other sites

Hello, I had earlier put this piece of code together for you but before I could post it

something else came up and took my attention away and in the meantime others

have provided you with the answer.

But rather than bin it here is my 2c worth ;-)

#include <array.au3>
$sInpVar = ""
$sOutPutStr = ""
$i=0


$sInpVar = "String sort; Chr by Chr" ;This variable should be set to the string you want to sort.
;$sInpVar = "azay" ;This variable should be set to the string you want to sort (yous in this case).

$aOutPutVar = StringSplit($sInpVar, "") ;This line creates an array to store your input string with one character per element. (See the helpfie for further details.)

_ArrayDisplay($aOutPutVar, "Before Sorting") ;Show the array as it stands before any further processing.

_ArraySort($aOutPutVar,0,1) ;Sort the array (Ascending Order) starting at array element 1.

_ArrayDisplay($aOutPutVar, "After Sorting") ;Show the array as it stands after sorting.


for $i=1 to $aOutPutVar[0] ;To use the data outside of the array you need
$sOutPutStr &=$aOutPutVar[$i] ;to rebuild it, i.e. piece it back together
next ;one character ata time.

MsgBox(64, " F.Y.I. ", "The actual variable in this script that is of use outside of " & @LF & "_arraydisplay is $sOutPutStr" & @LF & @LF & "which in this case contains "& @LF & "the rebuilt sorted string = " & $sOutPutStr )

Regards, DeMo.


Quote of the week:"BASIC programmers never die, they GOSUB and don't RETURN." -- UnknownWisdom of the ages:

  

  • I'd be unstoppable... if not for law enforcement and physics.
  • Marriage, the number 1 cause of divorce.
  • Don't steal... the government hates competition.
  • Irish Government Motto: We’ve got what it takes to take what you’ve got.
  • Birthdays are good for you. Statistics show that the people who have the most live the longest.
  • Failure is not an option. It comes bundled with your Microsoft product.-- Ferenc Mantfeld
  • If you learn from your mistakes, then why ain't I a genius?! -- Anonymous
  • Remember, live every day as if it was your last day! one day you will be right.
  • How is it one careless match can start a forest fire, but it takes a whole box to start a campfire?
  • Sure my system is secure, it just locked up again.
  • I haven't lost my mind; I have a tape back-up somewhere.  ~Author Unknown

Share this post


Link to post
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
Sign in to follow this  
Followers 0