Converting form "{X=12, Y=34}" to a Point

G

Guest

I'm using an xml schema (XSD) that has a point data in it, so when I'm saving
the schema (from memory with values) to an XML file, the point value is saved
in the form of: "{X=12, Y=34}" And that is very good.
Also when I'm loading the XML file with the schema to a DataSet, this
"{X=12, Y=34}" is converted nicely to a point.

I wish to do this same conversion from "{X=12, Y=34}" string pattern to a
point in memory (without XML schema), but I can't find how to.
The Point does not have the Parse method.
I did find the PointConverter.ConvertFrom("12, 34"), but its using a
different string format.

Is there a built in direct way to convert string in the form of "{X=12,
Y=34}" to a Point ?
 
G

Guest

I have the same problem with PointF.
Actually, the problem with PointF is event worse because there isn't any
equivalent for the PointConverter.
 
G

Guest

Sorry for the above empty post (-:

I have the same problem with PointF.
Actually, the problem with PointF is event worse because there isn't any
equivalent for the PointConverter.
 
S

Samuel R. Neff

You could parse it either with Regex or manual string manipulation.
Regex should work fine for this:

(X|Y)=(\d+)

BTW, I wouldn't sondier this "very good" XML or even acceptable if you
have control over the schema. XML should break up the data into all
it's constituent parts so once you've parsed out the XML you don't
have to do any additional parsing/converting/anything. So if you have

<point>{X=12, Y=34}</point>

You'd be a lot better off with

<point x="12" y="34" />

HTH,

Sam
 
E

Ed Minrights

I'm using an xml schema (XSD) that has a point data in it, so when I'm saving
the schema (from memory with values) to an XML file, the point value is saved
in the form of: "{X=12, Y=34}" And that is very good.
Also when I'm loading the XML file with the schema to a DataSet, this
"{X=12, Y=34}" is converted nicely to a point.

I wish to do this same conversion from "{X=12, Y=34}" string pattern to a
point in memory (without XML schema), but I can't find how to.
The Point does not have the Parse method.
I did find the PointConverter.ConvertFrom("12, 34"), but its using a
different string format.

Is there a built in direct way to convert string in the form of "{X=12,
Y=34}" to a Point ?

Can't you just convert it manually, just by getting rid of the bits
you don't need? This isn't pretty.. but should work..

string s = "{X=12, Y=34}";
s=s.Replace("{","").Replace("}","").Replace("X=","").Replace("Y=","");

Then you end up with a string in your required "13,34" format.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top