Sorting strings in word macro -


i need writing function take array of strings , sort new array of strings based on number characters in strings (ascending)? have following array of strings:

"abc53ddd", "2zzz2yyy", "14"

i need them listed

"14", "2zzz2yyy" , "abc53ddd"

as number characters in string 14, 22 , 53. can strip string number portions , sort array can't recover remaining characters list them in right order...

use ado disconnected recordset. see http://technet.microsoft.com/en-us/library/ee176578.aspx. fast , robust. imho, best.

'recordset definition dim rst new adodb.recordset 'must reference "microsoft activex data objects" 'or use automation (without reference) 'dim rst 'set rst = createobject("ador.recordset")  'fields definition - how many want (name, type, lenght) rst.fields.append "field1", adodb.datatypeenum.advarchar, 255 rst.fields.append "number", adodb.datatypeenum.adinteger  rst.open  'add values, example: dim rc adodb.record rst.addnew "field1", "abc53ddd" rst.addnew "field1", "2zzz2yyy" rst.addnew "field1", "14"  'make numbers string , store in field [number] dim reg new regexp 'or 'set reg = createobject("vbscript.regexp") reg.pattern = "\d" 'non-digit reg.global = true  rst.movefirst until rst.eof     rst!number = val(reg.replace(rst!field1, "")) 'delete non-digit     rst.movenext loop  'sort! rst.sort = "number asc" 'sort field1 ascending  'show output rst.movefirst until rst.eof     debug.print rst!field1, rst!number     rst.movenext loop 

Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -