The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Parsing Strings
Replies: 3   Last Post: Nov 13, 2012 7:19 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Kevin Ellis

Posts: 62
Registered: 11/29/10
Re: Parsing Strings
Posted: Nov 13, 2012 6:58 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

dpb <> wrote in message <k7uma4$f1d$>...
> On 11/13/2012 3:56 PM, Kevin Ellis wrote:
> > Hello,
> >
> > I have a question regarding parsing strings. Suppose I have a string:
> >
> > S = '42.714 GAL OF SMALL BOAT FUEL @3.699 PER GAL.'
> >
> > I have been trying to figure out a way to remove the numbers 42.714 and
> > 3.699 from the string. I have tried using 'sscanf' and 'regexp' to do
> > this. Using regexp I can find the index of the numbers:

> ...
> Is the text fixed or variable?
> If it's fixed and simply values change you can use
> x = sscanf(S,'%f GAL OF SMALL BOAT FUEL @%f');
> sscanf() isn't flexible in mixing conversion of string and numeric
> values but textscan() can.
> In regexp the expression needed would be (assuming F format,not E)
> s=regexp(S,'[0-9.]','match');
> then convert the resulting strings.
> --

The text is variable. The placement of the numbers will change and also the price per gallon may not appear at all. How can textscan() help me?


Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.