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

Home » Public Forums » archive » Re: String Processing Question
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: String Processing Question [message #42849] Thu, 03 March 2005 16:15 Go to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Benjamin Hornberger writes:

> Have a look at http://www.rsinc.com/codebank/search.asp?FID=311. No need
> for man pages, and it comes with a str_replace function.

Now there you go! (I'm not sure why the same article
is in the PDF file twice, unless you have to read the
material *at least* twice to get it, but if so, it's
a thoughtful addition.) I've already set it beside my
pillow for some bedtime reading tonight. :-)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Re: String Processing Question [message #42850 is a reply to message #42849] Thu, 03 March 2005 16:07 Go to previous messageGo to next message
Benjamin Hornberger is currently offline  Benjamin Hornberger
Messages: 258
Registered: March 2004
Senior Member
David Fanning wrote:
> Sobwom writes:
>
>
>> Try StrSplit():
>> animal = 'Coyote'
>> myString = 'My favorite animal is {1}.'
>> newString = StrJoin(StrSplit(myString, '\{1\}', /Regex, /Extract, $
>> /Preserve_Null), animal)
>
>
> Now *that's* what I'm talkin' about! :-)
>
> That whole "regular expression" business always makes
> my eyes glaze over. I think because everyone who explains
> it relies on the same UNIX man page. :-(

Have a look at http://www.rsinc.com/codebank/search.asp?FID=311. No need
for man pages, and it comes with a str_replace function.

Benjamin
Re: String Processing Question [message #42859 is a reply to message #42850] Thu, 03 March 2005 14:14 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Sobwom writes:

> Try StrSplit():
> animal = 'Coyote'
> myString = 'My favorite animal is {1}.'
> newString = StrJoin(StrSplit(myString, '\{1\}', /Regex, /Extract, $
> /Preserve_Null), animal)

Now *that's* what I'm talkin' about! :-)

That whole "regular expression" business always makes
my eyes glaze over. I think because everyone who explains
it relies on the same UNIX man page. :-(

Now I see how powerful it is. Really nice. My code
is back to being elegant again! Thanks a lot.

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Re: String Processing Question [message #42860 is a reply to message #42859] Thu, 03 March 2005 13:47 Go to previous messageGo to next message
Sobwom is currently offline  Sobwom
Messages: 2
Registered: March 2005
Junior Member
David Fanning wrote:
> Folks,
>
> My mind goes into shutdown mode whenever the subject of
> string processing comes up. It always has, I don't know
> why.
>
> I have a method of doing this, but is looks like
> a crock. Here is the situation.
>
> I have a variable:
>
> animal = 'Coyote'
>
> And I have a string:
>
> myString = 'My favorite animal is {1}.
>
> I want to replace "{1}" with "Coyote". What is the
> best way to do that, given that "{1}' can occur
> anywhere in the string?
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming: http://www.dfanning.com/

Try StrSplit():
animal = 'Coyote'
myString = 'My favorite animal is {1}.'
newString = StrJoin(StrSplit(myString, '\{1\}', /Regex, /Extract, $
/Preserve_Null), animal)
Re: String Processing Question [message #42981 is a reply to message #42860] Fri, 04 March 2005 08:32 Go to previous message
Norbert Hahn is currently offline  Norbert Hahn
Messages: 46
Registered: May 2003
Member
"Sobwom" <sobwom_joatamon@yahoo.com> wrote:

>> I have a variable:
>>
>> animal = 'Coyote'
>>
>> And I have a string:
>>
>> myString = 'My favorite animal is {1}.
>>

> Try StrSplit():
> animal = 'Coyote'
> myString = 'My favorite animal is {1}.'
> newString = StrJoin(StrSplit(myString, '\{1\}', /Regex, /Extract, $
> /Preserve_Null), animal)

Why is there a need to use /Regex and thusly quoting the braces?

Wouldn't

StrJoin(StrSplit(myString, '{1}', /Extract, /Preserve_Null), animal)

be sufficient?

Norbert
Re: String Processing Question [message #42997 is a reply to message #42850] Thu, 03 March 2005 17:58 Go to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
Benjamin Hornberger <benjamin.hornberger@stonybrook.edu> writes:
> David Fanning wrote:
>> Sobwom writes:
>>
>>> Try StrSplit():
>>> animal = 'Coyote'
>>> myString = 'My favorite animal is {1}.'
>>> newString = StrJoin(StrSplit(myString, '\{1\}', /Regex, /Extract, $
>>> /Preserve_Null), animal)
>> Now *that's* what I'm talkin' about! :-)
>> That whole "regular expression" business always makes
>> my eyes glaze over. I think because everyone who explains
>> it relies on the same UNIX man page. :-(
>
> Have a look at http://www.rsinc.com/codebank/search.asp?FID=311. No
> need for man pages, and it comes with a str_replace function.

...and the IDL Astronomy Library has the REPSTR() function.

Craig


--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@REMOVEcow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: IDL without X on Linux
Next Topic: String Processing Question

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

Current Time: Wed Oct 08 19:30:26 PDT 2025

Total time taken to generate the page: 0.00707 seconds