Jump to content

Recommended Posts

Posted

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

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
Posted

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

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...