T
Tom Cloyd
I'm trying to use gsub to do a number of transformations in an array of
strings. I find that when a particular transformation does NOT happen,
because the searched-for substring is not there, gsub returns nil. This
effectively ruins my output. I don't want nothing. I want the string
that's being processed, returned with or without any transformations. Is
there any alternative to testing for a return of nil before calling
gsub, so as to avoid the wiping out of my string? I've looked for
something to use other than String::gsub, and have not found anything.
Code:
filein = open( "{whatever}" )
fi = filein.readlines
delta = [ ["</p>", ''], ["</h1>", ''] ]
results = fi.collect do |x|
delta.each do |y|
debugger
x.gsub!(y[0], y[1])
end
end
t.
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tom Cloyd, MS MA, LMHC
Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< (e-mail address removed) >> (email)
<< TomCloyd.com >> (website & psychotherapy weblog)
<< sleightmind.wordpress.com >> (mental health issues weblog)
<< directpathdesign.com >> (web site design & consultation)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
strings. I find that when a particular transformation does NOT happen,
because the searched-for substring is not there, gsub returns nil. This
effectively ruins my output. I don't want nothing. I want the string
that's being processed, returned with or without any transformations. Is
there any alternative to testing for a return of nil before calling
gsub, so as to avoid the wiping out of my string? I've looked for
something to use other than String::gsub, and have not found anything.
Code:
filein = open( "{whatever}" )
fi = filein.readlines
delta = [ ["</p>", ''], ["</h1>", ''] ]
results = fi.collect do |x|
delta.each do |y|
debugger
x.gsub!(y[0], y[1])
end
end
t.
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tom Cloyd, MS MA, LMHC
Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< (e-mail address removed) >> (email)
<< TomCloyd.com >> (website & psychotherapy weblog)
<< sleightmind.wordpress.com >> (mental health issues weblog)
<< directpathdesign.com >> (web site design & consultation)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~