[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Finding numbers in a string
From: 
John W. Eaton 
Subject: 
Re: Finding numbers in a string 
Date: 
Wed, 20 Apr 2005 18:00:21 0400 
On 20Apr2005, E. Joshua Rigler <address@hidden> wrote:
 On Wed, 20050420 at 14:20, Søren Hauberg wrote:
 > Hi
 > I have a string containing both numbers and letters, and I want to
 > exctract the numbers and discard the letters. How do I do such a thing?
 >
 > /Søren


 There's probably a better way, but try this at the command line in
 Octave ('ismember' is an octaveforge function):


 Octave:1>
['ab1234567890cd'](find(ismember(toascii('ab1234567890cd'),[48:57])) )


 ([48:57]) are the ascii integers that correspond to the strings
 ['0':'9'], in case you were wondering)
How about something like
octave:1> x = "abc123def456"
x = abc123def456
octave:2> x(isdigit (x))
ans = 123456
jwe

Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
