On Wed, 18 Aug 2004 15:44:26 +0200, Niki Estner wrote:
There is no real equivalent to C++'s scanf or iostreams in .NET. The thing
that comes closest to these are regular expressions (C# syntax):
using System.Text.RegularExpressions;
...
Match m = Regex.Match(yourString,
@"^\s*([0-9.,]+)\s+([0-9.,]+)\s+([0-9.,]+)\s*$");
if (m.Success)
{
Console.WriteLine(System.Double.Parse(m.Groups[1].ToString()));
Console.WriteLine(System.Double.Parse(m.Groups[2].ToString()));
Console.WriteLine(System.Double.Parse(m.Groups[3].ToString()));
}
However, Regex's are far more powerful, and it may take some time to get
used to them. It's worth the effort though, IMO.
How would I write this in MC++? I tried this but got compilation errors:
#using <System.dll>
using namespace System::Text::RegularExpressions;
....
Match* m = Regex::Match(s,
"^\\s*([0-9.,]+)\\s+([0-9.,]+)\\s+([0-9.,]+)\\s*$");
if( m->Success ){
m_Northing = System::Double::Parse(m->Groups->Item(1)->ToString());
m_Easting = System::Double::Parse(m->Groups->Item(2)->ToString());
m_Elevation = System::Double::Parse(m->Groups->Item(3)->ToString());
}
(113) : error C2064: term does not evaluate to a function taking 1
arguments
(113) : error C2227: left of '->ToString' must point to class/struct/union
113 refers to m_Northing = ... line. Also, is the regular expression
written to be equivalent with the CS example? What does the @ at the start
of the CS RE mean?
Thanks!
--
Daniel
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?