comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Using STREGEX/STRMID
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Using STREGEX/STRMID [message #71280 is a reply to message #71277] Wed, 09 June 2010 12:23 Go to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
On Jun 9, 2:19 pm, fgg <fabioguimaraesgoncal...@gmail.com> wrote:
> 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)

You want the substring option of STREGEX,

str = stregex(str, '\(Label=([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
[Message index]
 
Read Message
Read Message
Previous Topic: Re: Object within an Object's Structure
Next Topic: Creating a sub array from an array

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Thu Oct 09 22:31:57 PDT 2025

Total time taken to generate the page: 0.47677 seconds