victor Posted March 15, 2012 Posted March 15, 2012 Hi i have a quick question , how do I split a string into int. I want to sort it numerically Spliting string into int Func _TestSort() $Matrix = "12,21,2,3,1" local $currentmatrix = StringSplit( $Matrix,",",0) _ArrayDisplay($currentmatrix) _ArraySort($currentmatrix) _ArrayDisplay($currentmatrix) EndFunc return - > 1 , 12 2, 21
czardas Posted March 15, 2012 Posted March 15, 2012 (edited) Using StringSplit creates an array of strings. You have to convert the strings to numbers.#include <Array.au3> _TestSort("12,21,2,3,1") Func _TestSort($Matrix) local $currentmatrix = StringSplit( $Matrix,",",0) _ArrayDisplay($currentmatrix) ; before conversion For $i = 1 To $currentmatrix[0] ; loop through the array $currentmatrix[$i] = Number($currentmatrix[$i]) ; Convert strings to numbers Next _ArraySort($currentmatrix, 0, 1) ; Start sorting from index 1 _ArrayDisplay($currentmatrix) ; after sorting EndFuncEditIf the array was created differntly, then the conversion may not be necessary. For example - if you simply declare an array of numbers like so:#include <Array.au3> Local $matrix[6] = [5,12,21,2,3,1] _ArraySort($matrix, 0, 1) _ArrayDisplay($matrix) Edited March 15, 2012 by czardas operator64 ArrayWorkshop
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now