Skip to main content
replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
Source Link

Update

I have found a new method for converting numeric strings using an internal function that was previously unknown to me. It is quite flexible, but its use requires care as bad input will crash the kernel. I have detailed my present understanding of the function here: ParseTable syntaxParseTable syntax.


Does this work for you?

hexNodeData /. 
 XMLElement[a_, {}, {s_String}] :> 
  XMLElement[a, {}, ImportString[s, "List"]]

I am using ImportString[s, "List"] to convert numbers in the 5.0000e+000 form.


You commented that this works, but is slow; indeed it is, but I don't have a better method for you, only alternatives. This question's answers give some:

How do you convert a string containing a number in C scientific notation to a Mathematica number?How do you convert a string containing a number in C scientific notation to a Mathematica number?

If your number were lower precision you could use Internal`StringToDouble but e.g. Internal`StringToDouble["3.141592653589793e+000"] gives $Failed["Bignum"]. Using ToExpression can be dangerous, because as Szabolcs states:

Whenever you use ToExpression on data read from a file, you make it possible to inject code into a program even inadvertently (one can never tell what sort of erroneous input the program might get by mistake).

Nevertheless it should be faster, so I present a method using it if you choose to risk it:

Block[{e},
 hexNodeData /. 
   XMLElement[a_, {}, {s_String}] :> 
    XMLElement[a, {}, {ToExpression @ s}]
      /. {e x_ + b_ :> x*10^b, e x_ :> x}
]

Update

I have found a new method for converting numeric strings using an internal function that was previously unknown to me. It is quite flexible, but its use requires care as bad input will crash the kernel. I have detailed my present understanding of the function here: ParseTable syntax.


Does this work for you?

hexNodeData /. 
 XMLElement[a_, {}, {s_String}] :> 
  XMLElement[a, {}, ImportString[s, "List"]]

I am using ImportString[s, "List"] to convert numbers in the 5.0000e+000 form.


You commented that this works, but is slow; indeed it is, but I don't have a better method for you, only alternatives. This question's answers give some:

How do you convert a string containing a number in C scientific notation to a Mathematica number?

If your number were lower precision you could use Internal`StringToDouble but e.g. Internal`StringToDouble["3.141592653589793e+000"] gives $Failed["Bignum"]. Using ToExpression can be dangerous, because as Szabolcs states:

Whenever you use ToExpression on data read from a file, you make it possible to inject code into a program even inadvertently (one can never tell what sort of erroneous input the program might get by mistake).

Nevertheless it should be faster, so I present a method using it if you choose to risk it:

Block[{e},
 hexNodeData /. 
   XMLElement[a_, {}, {s_String}] :> 
    XMLElement[a, {}, {ToExpression @ s}]
      /. {e x_ + b_ :> x*10^b, e x_ :> x}
]

Update

I have found a new method for converting numeric strings using an internal function that was previously unknown to me. It is quite flexible, but its use requires care as bad input will crash the kernel. I have detailed my present understanding of the function here: ParseTable syntax.


Does this work for you?

hexNodeData /. 
 XMLElement[a_, {}, {s_String}] :> 
  XMLElement[a, {}, ImportString[s, "List"]]

I am using ImportString[s, "List"] to convert numbers in the 5.0000e+000 form.


You commented that this works, but is slow; indeed it is, but I don't have a better method for you, only alternatives. This question's answers give some:

How do you convert a string containing a number in C scientific notation to a Mathematica number?

If your number were lower precision you could use Internal`StringToDouble but e.g. Internal`StringToDouble["3.141592653589793e+000"] gives $Failed["Bignum"]. Using ToExpression can be dangerous, because as Szabolcs states:

Whenever you use ToExpression on data read from a file, you make it possible to inject code into a program even inadvertently (one can never tell what sort of erroneous input the program might get by mistake).

Nevertheless it should be faster, so I present a method using it if you choose to risk it:

Block[{e},
 hexNodeData /. 
   XMLElement[a_, {}, {s_String}] :> 
    XMLElement[a, {}, {ToExpression @ s}]
      /. {e x_ + b_ :> x*10^b, e x_ :> x}
]
added 379 characters in body
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k

Update

I have found a new method for converting numeric strings using an internal function that was previously unknown to me. It is quite flexible, but its use requires care as bad input will crash the kernel. I have detailed my present understanding of the function here: ParseTable syntax.


Does this work for you?

hexNodeData /. 
 XMLElement[a_, {}, {s_String}] :> 
  XMLElement[a, {}, ImportString[s, "List"]]

I am using ImportString[s, "List"] to convert numbers in the 5.0000e+000 form.


You commented that this works, but is slow; indeed it is, but I don't have a better method for you, only alternatives. This question's answers give some:

How do you convert a string containing a number in C scientific notation to a Mathematica number?

If your number were lower precision you could use Internal`StringToDouble but e.g. Internal`StringToDouble["3.141592653589793e+000"] gives $Failed["Bignum"]. Using ToExpression can be dangerous, because as Szabolcs states:

Whenever you use ToExpression on data read from a file, you make it possible to inject code into a program even inadvertently (one can never tell what sort of erroneous input the program might get by mistake).

Nevertheless it should be faster, so I present a method using it if you choose to risk it:

Block[{e},
 hexNodeData /. 
   XMLElement[a_, {}, {s_String}] :> 
    XMLElement[a, {}, {ToExpression @ s}]
      /. {e x_ + b_ :> x*10^b, e x_ :> x}
]

Does this work for you?

hexNodeData /. 
 XMLElement[a_, {}, {s_String}] :> 
  XMLElement[a, {}, ImportString[s, "List"]]

I am using ImportString[s, "List"] to convert numbers in the 5.0000e+000 form.


You commented that this works, but is slow; indeed it is, but I don't have a better method for you, only alternatives. This question's answers give some:

How do you convert a string containing a number in C scientific notation to a Mathematica number?

If your number were lower precision you could use Internal`StringToDouble but e.g. Internal`StringToDouble["3.141592653589793e+000"] gives $Failed["Bignum"]. Using ToExpression can be dangerous, because as Szabolcs states:

Whenever you use ToExpression on data read from a file, you make it possible to inject code into a program even inadvertently (one can never tell what sort of erroneous input the program might get by mistake).

Nevertheless it should be faster, so I present a method using it if you choose to risk it:

Block[{e},
 hexNodeData /. 
   XMLElement[a_, {}, {s_String}] :> 
    XMLElement[a, {}, {ToExpression @ s}]
      /. {e x_ + b_ :> x*10^b, e x_ :> x}
]

Update

I have found a new method for converting numeric strings using an internal function that was previously unknown to me. It is quite flexible, but its use requires care as bad input will crash the kernel. I have detailed my present understanding of the function here: ParseTable syntax.


Does this work for you?

hexNodeData /. 
 XMLElement[a_, {}, {s_String}] :> 
  XMLElement[a, {}, ImportString[s, "List"]]

I am using ImportString[s, "List"] to convert numbers in the 5.0000e+000 form.


You commented that this works, but is slow; indeed it is, but I don't have a better method for you, only alternatives. This question's answers give some:

How do you convert a string containing a number in C scientific notation to a Mathematica number?

If your number were lower precision you could use Internal`StringToDouble but e.g. Internal`StringToDouble["3.141592653589793e+000"] gives $Failed["Bignum"]. Using ToExpression can be dangerous, because as Szabolcs states:

Whenever you use ToExpression on data read from a file, you make it possible to inject code into a program even inadvertently (one can never tell what sort of erroneous input the program might get by mistake).

Nevertheless it should be faster, so I present a method using it if you choose to risk it:

Block[{e},
 hexNodeData /. 
   XMLElement[a_, {}, {s_String}] :> 
    XMLElement[a, {}, {ToExpression @ s}]
      /. {e x_ + b_ :> x*10^b, e x_ :> x}
]
added 978 characters in body; deleted 4 characters in body
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k

Does this work for you?

hexNodeData /. 
 XMLElement[a_, {}, {s_String}] :> 
  XMLElement[a, {}, ImportString[s, "List"]]

I am using ImportString[s, "List"] to convert numbers in the 5.0000e+000 form.


You commented that this works, but is slow; indeed it is, but I don't have a better method for you, only alternatives. This question's answers give some:

How do you convert a string containing a number in C scientific notation to a Mathematica number?

If your number were lower precision you could use Internal`StringToDouble but e.g. Internal`StringToDouble["3.141592653589793e+000"] gives $Failed["Bignum"]. Using ToExpression can be dangerous, because as Szabolcs states:

Whenever you use ToExpression on data read from a file, you make it possible to inject code into a program even inadvertently (one can never tell what sort of erroneous input the program might get by mistake).

Nevertheless it should be faster, so I present a method using it if you choose to risk it:

Block[{e},
 hexNodeData /. 
   XMLElement[a_, {}, {s_String}] :> 
    XMLElement[a, {}, {ToExpression @ s}]
      /. {e x_ + b_ :> x*10^b, e x_ :> x}
]

Does this work for you?

hexNodeData /. 
 XMLElement[a_, {}, {s_String}] :> 
  XMLElement[a, {}, ImportString[s, "List"]]

I am using ImportString[s, "List"] to convert numbers in the 5.0000e+000 form.

Does this work for you?

hexNodeData /. 
 XMLElement[a_, {}, {s_String}] :> 
  XMLElement[a, {}, ImportString[s, "List"]]

I am using ImportString[s, "List"] to convert numbers in the 5.0000e+000 form.


You commented that this works, but is slow; indeed it is, but I don't have a better method for you, only alternatives. This question's answers give some:

How do you convert a string containing a number in C scientific notation to a Mathematica number?

If your number were lower precision you could use Internal`StringToDouble but e.g. Internal`StringToDouble["3.141592653589793e+000"] gives $Failed["Bignum"]. Using ToExpression can be dangerous, because as Szabolcs states:

Whenever you use ToExpression on data read from a file, you make it possible to inject code into a program even inadvertently (one can never tell what sort of erroneous input the program might get by mistake).

Nevertheless it should be faster, so I present a method using it if you choose to risk it:

Block[{e},
 hexNodeData /. 
   XMLElement[a_, {}, {s_String}] :> 
    XMLElement[a, {}, {ToExpression @ s}]
      /. {e x_ + b_ :> x*10^b, e x_ :> x}
]
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k
Loading