Jump to content

Require help with Regular Expression.

- - - - -

  • Please log in to reply
2 replies to this topic

#1
BotMaster

BotMaster

    Newbie

  • Members
  • Pip
  • 2 posts
I keep getting this error on two instances where I am using Regular Expression.
Below are the codes of two classes on which I am getting this error.
Please can someone help me correct this error?
The error reads like--->
the best overload method match for System.Text.RegularExpressions.Regex.Match has some invalid arguments

I am getting this error at str2 in the below 2 codes:

public int GetLength(string path)

        {

            string output = this.GetOutput(path);

            string str2 = "";

            int num = 0;

            if ((output == "") && (output.Contains("Invalid data found when processing input") || output.Contains("could not find codec parameters")))

            {

                return 0;

            }

            string str3 = path;

            try

            {

                str2 = Regex.Match(output, @"(?:Duration\:)(.*?)(?:,)", 0x10).Groups[1].Value.Trim();

            }

            catch (Exception)

            {

                str2 = "";

            }

            if (str2 != "")

            {

                try

                {

                    num = int.Parse(str2.Split(new char[] { ':' })[0]) * 0xe10;

                    num += int.Parse(str2.Split(new char[] { ':' })[1]) * 60;

                    num += (int)double.Parse(str2.Split(new char[] { ':' })[2]);

                }

                catch (Exception)

                {

                }

            }

            return num;

        }


public int GetLength(string path)

        {

            string input = path;

            string str2 = "";

            int num = 0;

            if ((input == "") && (input.Contains("Invalid data found when processing input") || input.Contains("could not find codec parameters")))

            {

                return 0;

            }

            string str3 = path;

            try

            {

                str2 = Regex.Match(input, @"(?:Duration\:)(.*?)(?:,)", 0x10).Groups[1].Value.Trim();

            }

            catch (Exception)

            {

                str2 = "";

            }

            if (str2 != "")

            {

                try

                {

                    num = int.Parse(str2.Split(new char[] { ':' })[0]) * 0xe10;

                    num += int.Parse(str2.Split(new char[] { ':' })[1]) * 60;

                    num += (int)double.Parse(str2.Split(new char[] { ':' })[2]);

                }

                catch (Exception)

                {

                }

            }

            return num;

        }


I am getting this error at str in the below code:

public void GetSize(string result)

        {

            string str = "";

            try

            {

                string input = result;

                if (input.Contains("Video:"))

                {

                    input = input.Substring(input.IndexOf("Video:"));

                }

                str = Regex.Match(input, @"\d+x\d+", 0x10).Groups[0].Value;

                this.width = double.Parse(str.Split(new char[] { ':' })[0]);

                this.height = double.Parse(str.Split(new char[] { ':' })[1]);

            }

            catch (Exception)

            {

            }

        }


Any help would be greatly appreciated.

#2
Momerath

Momerath

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 242 posts
You can't just specify a numeric value in place of an enum, you need to cast it into the enum:
str = Regex.Match(input, @"\d+x\d+", 0x10).Groups[0].Value;


// should be

str = Regex.Match(input, @"\d+x\d+", (RegexOptions)0x10).Groups[0].Value;

As an example.

#3
BotMaster

BotMaster

    Newbie

  • Members
  • Pip
  • 2 posts
Hi,
Thanks for the help. Worked great. Also learned a thing about Regex and c#




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users