473,402 Members | 2,046 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

RegEx.MatchCollection.CopyTo method fails!

Has anyone had any luck getting this CopyTo method to work?

I can iterate through a MatchCollection and move each Match.Value to
the System.Array without a problem. I just can't figure out why the
CopyTo method will not work.

Example:
// Find all the Tables in an html string (page)
MatchCollection mc = Regex.Matches(html, "<table.+</table");
string[] t = new string[mc.Count];
mc.CopyTo(t, 0);

ERROR HERE IS:
An unhandled exception of type 'System.InvalidCastException' occurred
in mscorlib.dll

Additional information: At least one element in the source array could
not be cast down to the destination array type.

-*-*-*-*-*
In my particular case, mc.Count = 4. If I use a for each loop to
iterate through and set each element of the array, there is no problem
whatsoever.

TIA for any information that may help me to understand why the CopyTo
did not work.

--
John Wood a.k.a. Mortimer Schnurd
Nov 16 '05 #1
2 6500

The array t should be an array of Match objects, not strings.

Brian Davis
http://www.knowdotnet.com

"Mortimer Schnurd" <fu**********@hotsmail.com> wrote in message
news:s3********************************@4ax.com...
Has anyone had any luck getting this CopyTo method to work?

I can iterate through a MatchCollection and move each Match.Value to
the System.Array without a problem. I just can't figure out why the
CopyTo method will not work.

Example:
// Find all the Tables in an html string (page)
MatchCollection mc = Regex.Matches(html, "<table.+</table");
string[] t = new string[mc.Count];
mc.CopyTo(t, 0);

ERROR HERE IS:
An unhandled exception of type 'System.InvalidCastException' occurred
in mscorlib.dll

Additional information: At least one element in the source array could
not be cast down to the destination array type.

-*-*-*-*-*
In my particular case, mc.Count = 4. If I use a for each loop to
iterate through and set each element of the array, there is no problem
whatsoever.

TIA for any information that may help me to understand why the CopyTo
did not work.

--
John Wood a.k.a. Mortimer Schnurd

Nov 16 '05 #2
On Wed, 16 Jun 2004 16:31:49 -0400, in msg
<#c**************@TK2MSFTNGP09.phx.gbl>, "Brian Davis" <@> wrote:

The array t should be an array of Match objects, not strings.

Brian Davis
http://www.knowdotnet.com

That was it!

Thanks for the help.

MatchCollection mc = Regex.Matches(html, "<table.+</table");
Match[] t = new Match[mc.Count];
mc.CopyTo(t,0);

--
JW
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Tap | last post by:
I would like to parse the following string with as little code as possible. stringValue = "Email Message ID:TAPASVI to...
2
by: Mortimer Schnurd | last post by:
Hi All, I am a VB 6 programmer who is now trying to learn C#. In doing so, I am trying to convert some of my VB modules to C#. I routinely user Reg Expressions in VB and am having some trouble...
1
by: Mortimer Schnurd | last post by:
Has anyone had any luck getting this CopyTo method to work? I can iterate through a MatchCollection and move each Match.Value to the System.Array without a problem. I just can't figure out why...
2
by: D | last post by:
My first attempt at this and I'm searching formulas like so RIGHT(TEXT(A15,'yy'),1)*1000+A15-CONCATENATE(1,'-','jan','-',TEXT(A15,'yy'))+1 I want to extract the row / col coordinates (A15 in...
1
by: DKode | last post by:
I have the following regex that I am using: Match match = Regex.Match(global, "%(?<column>.+?)%"); my input string (global) is this: "something\%username%\somethingelse\%match2%\some\%match3%...
8
by: Richard Lionheart | last post by:
Hi All, I tried using RegEx, but the compiler barfed with "The type of namespace 'RegEx' could not be found. Prior to this, I had the same problem with MatchCollection, but discovered it's...
5
by: Chris | last post by:
How Do I use the following auto-generated code from The Regulator? '------------------------------------------------------------------------------ ' <autogenerated> ' This code was generated...
6
by: Sačo Zagoranski | last post by:
Hi, could someone help me putting together a regex expression for my problem? I need my search filter to treat spaces and commas in the query the same way no matter how many there are... ...
6
by: Gary Bond | last post by:
Hi All, Being a bit of a newbie with regex, I am confused when using word boundaries. For instance, I want to replace all the stand alone '.5k' that occur in an input string, with 500. In other...
2
by: O.B. | last post by:
In the following example, the Matches operation never returns 4 matches as I am expecting. What's wrong with my syntax? private const string DOUBLE_REGEX = @"?*?*"; private const string...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.