help-octave
[Top][All Lists]
Advanced

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

String Index


From: Thomas D. Dean
Subject: String Index
Date: Sun, 26 Jun 2016 19:56:37 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0

I have a string, 87 characters. containing pairs of parens enclosing characters. The number of chars enclosed is not constant. There are 2 to 5 pairs of parens. How do I construct the index to vectorize this?

> n=numel(str)
n =  87
> lp = [1:n](str == "(");
> rp = [1:n](str == ")");
> ## check to see if parens paired and lp < rp
> [lp', rp']
ans =
   38   47
   54   57
   66   73
   85   87

I want to extract values from str using lp and rp

> [ str(lp(1):rp(1));
>   str(lp(2):rp(2));
>   str(lp(3):rp(3));
>   str(lp(4):rp(4)) ]
ans =
(10^20 kg)
(km)
(kg/m^3)
(1)

Tom Dean



reply via email to

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