News:

Function Finder  Find all the functions within source code files

Main Menu

Sorting Delimited Integers within a String

Started by kevin, February 23, 2010, 08:11:37 AM

Previous topic - Next topic

kevin

 This cuts a string up and sorts the integer values within it.    Which is nothing more than SplitToArray/SortArray function.   But anyway..


Version for PlayBASIC 1.64k2 / PBFX 1.76
PlayBASIC Code: [Select]
s$="9-20-33-45-55-11"

Dim Numbers(1000)

; split the
Count=SplitTOArray(S$,"-",NUmbers(),0)

; Sort the array
SortArray Numbers(),0,Count-1

; rebuild the string
For lp=0 to Count-1
R$+=str$(Numbers(lp))
if lp<Count-1 then R$+="-"
next

; display original string
print S$
; display sorted string
print R$

Sync
waitkey
[/code]



Version for PlayBASIC V1.63 (LEARNING EDITION)

[code]
s$="9-20-33-45-55-11"

Dim Numbers(1000)

; split the
Count=SplitTOArray(S$,"-",NUmbers(),0)

; Sort the array
SortArray Numbers(),0,Count-1

; rebuild the string
For lp=0 to Count-1
R$=r$+str$(Numbers(lp))
if lp<Count-1 then R$=r$+"-"
next

; display original string
print S$
; display sorted string
print R$

Sync
waitkey