On Tue, Jul 20, 2004 at 02:30:50PM +0300, Serghei Amelian wrote:
> On Tuesday 20 July 2004 14:20, Alex Popa wrote:
> > On Tue, Jul 20, 2004 at 02:11:02PM +0300, Mihai Gheorghe wrote:
> > > stie cineva de ce nu pot folosi expr cu stringuri (asa cum merge pe
> > > orice linux)?
> > >
> > > #!/bin/sh
> > >
> > > b="jk adsf"
> > > x=`expr length $b`
> > > echo $x
> > > __________________
> > >
> > > la length problema e simpla deoarece pot inlocui cu x=${#b}, dar
> > > cum pot inlocui "expr index" ???
> >
> > Incearca x=`expr length "$b"`
> >
> > Subliniez ghilimelele.
> >
> > Alex
> 
> Se pare ca implementarea expr din freebsd nu are length. Ar merge 
> folosit awk:
> 
> index(s, t)             returns the index of the string t in the string
>                                s, or 0 if t is not present.
> 
> length([s])             returns  the  length  of  the  string s, or the
>                                length of $0 if s is not supplied.

Un truc pentru length am postat deja...

Pentru index, daca nu deranjeaza sa afli indexul *ultimei* aparitii a
stringului, combinam diverse chestii din exemplele lor:

expr cucubaubau : '\(.*\)bau' : '.*' => o sa zica 7 (acolo incepe al
doilea "bau").  Principiul e ca iau stringul dinainte de match, si vad
ce lungime are.  Din nefericire, varianta asta intoarce 0 si daca
stringul apare fix la inceput, si daca nu e gasit, deci trebuie sa ai
grija.

Have fun
        Alex

------------+-------------------------------------------------------
Alex Popa,  |  "Computer science is no more about computers than
[EMAIL PROTECTED]|     astronomy is about telescopes" -- E. W. Dijkstra
------------+-------------------------------------------------------
__________________________________________________________
Send 'unsubscribe rofug' to [EMAIL PROTECTED] to unsubscribe

Raspunde prin e-mail lui