Gauss Posted October 24, 2014 Posted October 24, 2014 1 small question $str = 'MATHS: 95 04 PHYSICS:78 6o ENGLISH: 82' Here 04 and 6o are garbage values Lets say I just want to get the marks scored in MATHS and ENGLISH how do I get it
jguinch Posted October 24, 2014 Posted October 24, 2014 (edited) ? $str = 'MATHS: 95 04 PHYSICS:78 6o ENGLISH: 82' $aScores = StringRegExp($str, "(MATHS|PHYSICS):\h*(\d+)", 3) For $i = 0 To UBound($aScores) - 1 Step 2 ConsoleWrite($aScores[$i] & " = " & $aScores[$i + 1] & @CRLF) Next Edit : *Urgent* is not necessary Edited October 24, 2014 by jguinch Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
kylomas Posted October 24, 2014 Posted October 24, 2014 another way... #include <array.au3> $str = 'MATHS: 95 04 PHYSICS:78 6o ENGLISH: 82' ;$aScores = StringRegExp($str, "\w+:\h*\d+", 3) ; get all courses $aScores = StringRegExp($str, "(?:MATHS|ENGLISH):\h*\d+", 3) ; get just MATHS and ENGLISH _arraydisplay($aScores) Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
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