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

Home » Public Forums » archive » 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
String Processing Question [message #42864] Thu, 03 March 2005 12:42 Go to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
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/
Re: String Processing Question [message #42980 is a reply to message #42864] Fri, 04 March 2005 08:40 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Norbert Hahn writes:

> 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?

IDL> animal = 'Coyote'
IDL> myString = 'My favorite animal is {1}.
IDL> print, StrJoin(StrSplit(myString, '{1}', /Extract, /Preserve_Null),
animal)
My favorite animal is CoyoteCoyoteCoyote.

It's good for emphasis, but beyond that, I think
the previous example is better. :-)

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 #42993 is a reply to message #42864] Fri, 04 March 2005 01:06 Go to previous message
R.Bauer is currently offline  R.Bauer
Messages: 1424
Registered: November 1998
Senior 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}.

my_string=replace_string(my_string,'{1}',animal)

You find this function in our library
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_source/idl _html/dbase
replace_string_dbase.pro.html

This was written before the regex stuff was implemented in idl.

cheers
Reimar


--
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
http://www.fz-juelich.de/icg/icg-i/
============================================================ ======
a IDL library at ForschungsZentrum Juelich
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_lib_intro. html
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: String Processing Question
Next Topic: Arrays suck. Loops rock.

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

Current Time: Sat Nov 29 07:24:39 PST 2025

Total time taken to generate the page: 1.36212 seconds