Re: String Processing Question [message #42849] |
Thu, 03 March 2005 16:15  |
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 #42860 is a reply to message #42859] |
Thu, 03 March 2005 13:47   |
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  |
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  |
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
------------------------------------------------------------ --------------
|
|
|