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

Home » Public Forums » archive » Re: How to extract sub-string from array
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: How to extract sub-string from array [message #61697] Mon, 28 July 2008 02:14 Go to next message
Foldy Lajos is currently offline  Foldy Lajos
Messages: 268
Registered: October 2001
Senior Member
On Mon, 28 Jul 2008, Ian Dean wrote:

> Hi,
> I've got an array such as ['Test_data;01', 'Test_data;005',
> 'New_dat;100','Old_dat'....]
>
> What I'd like to do but haven;t achieved is create an array of the extension
> past the ';'
> i.e. ['01','005','100',''....]
> I've tried this:
>
> semi_colon = STREGEX(Data_array, ';')
> ; This gives an array of positions [9, 9, 7,-1...]
>
> I can replace the -1s with string lengths easily enough giving [9, 9, 7,
> 7...]
> However, I can't seem to extract the sub-strings
> I tried
> Extension = STRMID(Data_array, semi_colon + 1)
> but this gives me a 2-d array and no clue which elements I require.
> I suspect that there is some arcane use of histogram, but I am not brave
> enough to try.
>
> I know why the STRMID is failing, because the help says so, because both
> arguments are arrays.
> Looping though the list is not an option as in reality I have an array
> length in the order of 500,000
>
> Any help would be appreciated,
> Regards,
> Ian


Try this: STRMID(STREGEX(Data_array, ';.*', /extract), 1)

regards,
lajos
Re: How to extract sub-string from array [message #61698 is a reply to message #61697] Mon, 28 July 2008 02:12 Go to previous messageGo to next message
Allan Whiteford is currently offline  Allan Whiteford
Messages: 117
Registered: June 2006
Senior Member
Ian Dean wrote:
> Hi,
> I've got an array such as ['Test_data;01', 'Test_data;005',
> 'New_dat;100','Old_dat'....]
>
> What I'd like to do but haven;t achieved is create an array of the extension
> past the ';'
> i.e. ['01','005','100',''....]
> I've tried this:
>
> semi_colon = STREGEX(Data_array, ';')
> ; This gives an array of positions [9, 9, 7,-1...]
>
> I can replace the -1s with string lengths easily enough giving [9, 9, 7,
> 7...]
> However, I can't seem to extract the sub-strings
> I tried
> Extension = STRMID(Data_array, semi_colon + 1)
> but this gives me a 2-d array and no clue which elements I require.
> I suspect that there is some arcane use of histogram, but I am not brave
> enough to try.
>
> I know why the STRMID is failing, because the help says so, because both
> arguments are arrays.
> Looping though the list is not an option as in reality I have an array
> length in the order of 500,000
>
> Any help would be appreciated,
> Regards,
> Ian
>
>

Ian,

How about:

numbers=fix(reform((stregex(data_array,';([0-9]+)$',/extract ,/sub))[1,*]))

(you might want to change "fix" to "long" if you have numbers over
32,768ish).

Thanks,

Allan
Re: How to extract sub-string from array [message #61759 is a reply to message #61697] Tue, 29 July 2008 01:33 Go to previous messageGo to next message
Ian Dean is currently offline  Ian Dean
Messages: 26
Registered: January 2000
Junior Member
"F�LDY Lajos" <foldy@rmki.kfki.hu> wrote in message
news:Pine.LNX.4.64.0807281111470.17704@bifur.rmki.kfki.hu...
>
> On Mon, 28 Jul 2008, Ian Dean wrote:
>
>> Hi,
>> I've got an array such as ['Test_data;01', 'Test_data;005',
>> 'New_dat;100','Old_dat'....]
>>
>> What I'd like to do but haven;t achieved is create an array of the
>> extension
>> past the ';'
>> i.e. ['01','005','100',''....]
>> I've tried this:
>>
>> semi_colon = STREGEX(Data_array, ';')
>> ; This gives an array of positions [9, 9, 7,-1...]
>>
>> I can replace the -1s with string lengths easily enough giving [9, 9, 7,
>> 7...]
>> However, I can't seem to extract the sub-strings
>> I tried
>> Extension = STRMID(Data_array, semi_colon + 1)
>> but this gives me a 2-d array and no clue which elements I require.
>> I suspect that there is some arcane use of histogram, but I am not brave
>> enough to try.
>>
>> I know why the STRMID is failing, because the help says so, because both
>> arguments are arrays.
>> Looping though the list is not an option as in reality I have an array
>> length in the order of 500,000
>>
>> Any help would be appreciated,
>> Regards,
>> Ian
>
>
> Try this: STRMID(STREGEX(Data_array, ';.*', /extract), 1)
>
> regards,
> lajos
>
Thanks to all. It's so simple when you know how!!
Regards,
Ian
Re: How to extract sub-string from array [message #61805 is a reply to message #61759] Thu, 31 July 2008 00:36 Go to previous message
Ian Dean is currently offline  Ian Dean
Messages: 26
Registered: January 2000
Junior Member
Hi again,

Although I had some good help on this problem, it has now got a bit more
complicated with more than one semicolon in a string:
[ 'Test;1;02;1234', 'Another_test;;2'...]
Has anyone come across an array version of STRSPLIT?
It would be great to be able to produce n string arrays of each part of
the original:

names = ['Test','Another_test'...]
sub_1 = ['1',''...]
sub_2 = ['02','2'...]
sub_3 = ['1234',''...]

Regards,
Ian

"Ian Dean" <ian.d.dean@baesystems.com> wrote in message
news:488ed1bf$1_1@glkas0286.greenlnk.net...
>
> "F�LDY Lajos" <foldy@rmki.kfki.hu> wrote in message
> news:Pine.LNX.4.64.0807281111470.17704@bifur.rmki.kfki.hu...
>>
>> On Mon, 28 Jul 2008, Ian Dean wrote:
>>
>>> Hi,
>>> I've got an array such as ['Test_data;01', 'Test_data;005',
>>> 'New_dat;100','Old_dat'....]
>>>
>>> What I'd like to do but haven;t achieved is create an array of the
>>> extension
>>> past the ';'
>>> i.e. ['01','005','100',''....]
>>> I've tried this:
>>>
>>> semi_colon = STREGEX(Data_array, ';')
>>> ; This gives an array of positions [9, 9, 7,-1...]
>>>
>>> I can replace the -1s with string lengths easily enough giving [9, 9, 7,
>>> 7...]
>>> However, I can't seem to extract the sub-strings
>>> I tried
>>> Extension = STRMID(Data_array, semi_colon + 1)
>>> but this gives me a 2-d array and no clue which elements I require.
>>> I suspect that there is some arcane use of histogram, but I am not brave
>>> enough to try.
>>>
>>> I know why the STRMID is failing, because the help says so, because both
>>> arguments are arrays.
>>> Looping though the list is not an option as in reality I have an array
>>> length in the order of 500,000
>>>
>>> Any help would be appreciated,
>>> Regards,
>>> Ian
>>
>>
>> Try this: STRMID(STREGEX(Data_array, ';.*', /extract), 1)
>>
>> regards,
>> lajos
>>
> Thanks to all. It's so simple when you know how!!
> Regards,
> Ian
>
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Surface fitting image with missing data
Next Topic: idlworkspace trouble

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

Current Time: Wed Oct 08 17:06:17 PDT 2025

Total time taken to generate the page: 0.00625 seconds