help-octave
[Top][All Lists]
Advanced

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

Re: Search string in cell string?


From: PhilipNienhuis
Subject: Re: Search string in cell string?
Date: Tue, 6 Dec 2011 12:13:12 -0800 (PST)

Jordi Gutiérrez Hermoso-2 wrote
> 
> How can you get the index of where in a cell string a specified search
> term occurs, if it does at all?
> 
> Assuming the cell string were ordered, you could binary search. But
> how can you compare strings ASCIIbetically? The strcmp function only
> gives you equality or not, not order.
> 
> So what can be done?
> 

(Hopefully I interpret your question correctly)

Many string functions operate on cell arrays too. And you can define your
own cell function.

In the dev version of strread.m Rik and I have included several examples,
mine may be a bit ugly (as I'm no guru like Rik) but They Work. 
See esp. lines 380- 570.

Moreover:

octave-3.5.0+:13> 'a' < 'b'
ans =  1
octave-3.5.0+:14> 'a' > 'b'
ans = 0

so you can directly compare characters. (It might be more neat to cast them
to e.g., int8)

Philip


--
View this message in context: 
http://octave.1599824.n4.nabble.com/Search-string-in-cell-string-tp4165511p4166283.html
Sent from the Octave - General mailing list archive at Nabble.com.


reply via email to

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