Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a big array of data that I imported from a lot of XML files. To get the data, among other manipulations, I use this function:

Cases[xml,XMLElement[nodeName,_,a_]-> a,\[Infinity]]

When I get my final array, I have a lot of number fields that are as String and that I need to convert into Number. To do that I created this function:


The problem is that I have strings with "??" characters, so if o use clean on it as for example:

clean[{"asd??asd", "123.3"}]

Mathematica try to interpret the first element as context ones. And I get:


How to avoid it? How can I improve my clean function, or the way I load de XML?

share|improve this question
up vote 7 down vote accepted

Rather than applying ToExpression and then NumberQ, perhaps you could just use StringMatchQ with NumberString in the first place.

StringMatchQ["assd??asd", NumberString]
(* Out: False *)

StringMatchQ["123.3", NumberString]
(* True *)
share|improve this answer
Nice! Will try it. Nice tip. – Murta Nov 2 '12 at 20:22
It worked like a charm. Tks – Murta Nov 3 '12 at 15:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.