[dba-VB] C# Regex? - Ignore :-)

Michael Maddison michael at ddisolutions.com.au
Thu Mar 29 22:42:51 CDT 2012


Ooops,

Michael M

-----Original Message-----
From: dba-vb-bounces at databaseadvisors.com
[mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Michael
Maddison
Sent: Friday, 30 March 2012 2:41 PM
To: Discussion concerning Visual Basic and related programming issues.
Subject: [dba-VB] C# Regex?

Adam,

My strings could look like any of these
	1 sec 
	11 sec
	1 min 5 sec
	1 min 26 sec
	1 hr  1 min 5 sec
	1 hr  12 min 26 sec	

The goal is to get total # of seconds but splitting into a
MatchCollection would do.


        private int GetRecLength ( string value )
        {
            //x hr 3 min 8 sec
            string hr = string.Empty, min = string.Empty, sec =
string.Empty;
            int val = 0;
            //sec = value.Substring ( value.Length - 6, 2 );
            //min = value.Substring(value.Length - 


            //@"(^[0-9]*$)"  min\s(?<sec>\d\S+)

            Regex r = new Regex ( @"[0-9]+" );
            MatchCollection mc = r.Matches ( value );
            
            
            min = mc [ 0 ].Value;
            sec = mc [ 1 ].Value;
	
           //Change to looping through collection members
            if ( !string.IsNullOrEmpty ( min ) ) val = Convert.ToInt32 (
min ) * 60;
            if ( !string.IsNullOrEmpty ( sec ) ) val = Convert.ToInt32 (
sec ) + val;
            // 
            //(?<min>\d\S+\s)min\s(?<sec>\d\S+)

            return val;
        }


Cheers

Michael M

_______________________________________________
dba-VB mailing list
dba-VB at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/dba-vb
http://www.databaseadvisors.com


-----
No virus found in this message.
Checked by AVG - www.avg.com
Version: 10.0.1424 / Virus Database: 2113/4903 - Release Date: 03/29/12



More information about the dba-VB mailing list