[Top][All Lists]

[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 20-Apr-2005, E. Joshua Rigler <address@hidden> wrote:

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

How about something like

  octave:1> x = "abc123def456"
  x = abc123def456
  octave:2> x(isdigit (x))
  ans = 123456


Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:
How to fund new projects:
Subscription information:

reply via email to

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