Sign in to follow this  
Followers 0
Gauss

Extract Grouped Digits from String *Urgent*

3 posts in this topic

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by jguinch

Share this post


Link to post
Share on other sites

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

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