help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Finding numbers in a string


From: Hall, Benjamin
Subject: RE: Finding numbers in a string
Date: Wed, 20 Apr 2005 17:58:03 -0400

Taking that a little further...the following is a hack that will work for
integers, it gets trickier to check for floating point values


octave:46> some_str = "alpha 1 is 10 bigger than 33, I don't 4, 12,55? 2";
octave:47> nums = "0123456789";
octave:48> idx = !ismember( double(some_str), double(nums) );
octave:49> some_str(idx) = ' ';
octave:50> values = sscanf( some_str, '%d' )
values =

   1
  10
  33
   4
  12
  55
   2



-----Original Message-----
From: E. Joshua Rigler [mailto:address@hidden
Sent: Wednesday, April 20, 2005 5:20 PM
To: Søren Hauberg
Cc: Help-Octave
Subject: Re: Finding numbers in a string


On Wed, 2005-04-20 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 octave-forge 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)

-EJR





-------------------------------------------------------------
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
-------------------------------------------------------------



-------------------------------------------------------------
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
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]