0
$\begingroup$

How can I check if the string contains a real or integer number, space and string?

e.g. StrCheck["156 af"] = true StrCheck["15.6 af"] = true

StrCheck["a 156 af"] = false StrCheck["a 1.56 af"] = false

Thank you!

$\endgroup$
  • $\begingroup$ Your examples are not really conclusive. What are the criteria for the decision? $\endgroup$ – Yves Klett Mar 30 '15 at 15:29
  • 1
    $\begingroup$ StringMatchQ[string,DigitCharacter .. ~~ __]? $\endgroup$ – Algohi Mar 30 '15 at 15:34
  • $\begingroup$ StringMatchQ[rhs, DigitCharacter .. ~~ ___ ~~ LetterCharacter] $\endgroup$ – SuTron Mar 30 '15 at 15:37
1
$\begingroup$
f = StringMatchQ[#, NumberString ~~ " " ~~ __] &;

f /@ {"156 af", "15.6 af", "a 156 af", "a 1.56 af"}

{True, True, False, False}

See StringMatchQ, StringExpression, NumberString, BlankSequence, Slot, Function

Related: How can I improve NumberString?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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