From the string x = "DIMENSION: 17" I want to extract the integer and load it into n (in general, the string need not end in 17). This command works:
n = StringCases[x, "DIMENSION:" ~~ Whitespace ~~ (y : DigitCharacter ..) -> y] // First // ToExpression;
But there must be a much simpler way. What is it? Thankx.
You can also try--
StringSplit[x][] // ToExpression
Girish, this is perfect, exactly what I sought. Thanks.
Is this simpler?
n = StringReplace[x, RegularExpression["\\D+"] -> " "] // ToExpression
which will handle any non-digit characters before and/or after the digits, but won't handle several groups of digits.
Bill, this is shorter and thus better -- didn't think of using RegularExpression. Girish provided the solution I hoped was out there, and both replies are useful. Thanks.