Hello,
I'd like to get the "label" (i.e. 1033) from this string:
IDL> str = '; ROI name: EVF: Layer: pts_slant.shp (Label=1033)'
....and I was wondering if there is a more elegant/efficient way of
doing this than:
IDL> pos0 = stregex(str, '=')+1
IDL> posn = stregex(str, ')')
IDL> print, strmid(str, pos0, posn-pos0)
IDL prints:
1033
Thanks!
|
|
0
|
|
|
|
Reply
|
fabioguimaraesgoncalves (26)
|
6/9/2010 6:19:09 PM |
|
On Jun 9, 2:19=A0pm, fgg <fabioguimaraesgoncal...@gmail.com> wrote:
> Hello,
>
> I'd like to get the "label" (i.e. 1033) from this string:
>
> IDL> str =3D '; ROI name: EVF: Layer: pts_slant.shp (Label=3D1033)'
>
> ...and I was wondering if there is a more elegant/efficient way of
> doing this than:
>
> IDL> pos0 =3D stregex(str, '=3D')+1
> IDL> posn =3D stregex(str, ')')
> IDL> print, strmid(str, pos0, posn-pos0)
You want the substring option of STREGEX,
str =3D stregex(str, '\(Label=3D([0-9]*)\)', /extract, /sub)
print, str[1]
1033
The zeroth substring is the full match.
The first substring is the one enclosed in parentheses. It's a little
confusing because the () are used to enclose regex substrings and \(\)
are the literal parentheses expected to appear in the string.
Craig
|
|
0
|
|
|
|
Reply
|
Craig
|
6/9/2010 7:23:55 PM
|
|
On Jun 9, 12:23=A0pm, Craig Markwardt <craig.markwa...@gmail.com> wrote:
> On Jun 9, 2:19=A0pm, fgg <fabioguimaraesgoncal...@gmail.com> wrote:
>
> > Hello,
>
> > I'd like to get the "label" (i.e. 1033) from this string:
>
> > IDL> str =3D '; ROI name: EVF: Layer: pts_slant.shp (Label=3D1033)'
>
> > ...and I was wondering if there is a more elegant/efficient way of
> > doing this than:
>
> > IDL> pos0 =3D stregex(str, '=3D')+1
> > IDL> posn =3D stregex(str, ')')
> > IDL> print, strmid(str, pos0, posn-pos0)
>
> You want the substring option of STREGEX,
>
> str =3D stregex(str, '\(Label=3D([0-9]*)\)', /extract, /sub)
> print, str[1]
> 1033
>
> The zeroth substring is the full match.
> The first substring is the one enclosed in parentheses. =A0It's a little
> confusing because the () are used to enclose regex substrings and \(\)
> are the literal parentheses expected to appear in the string.
>
> Craig
Perfect. Thank you, Craig.
|
|
0
|
|
|
|
Reply
|
fgg
|
6/9/2010 9:01:17 PM
|
|
|
2 Replies
328 Views
(page loaded in 0.12 seconds)
Similiar Articles:7/29/2012 6:47:50 AM
|