| String Processing Question [message #42864] |
Thu, 03 March 2005 12:42  |
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  |
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/
|
|
|
|
|
|