Removing just leading and trailing newline characters

Hi:

I am using FCKeditor in one of my form, when i copy and paste something
into it using WordPaste, it appends few newlines at the beginning and at
the end.
How can i strip just those \n without effecting the inbetween newlines
and the formatting.

TIA,
Priya

you may use strip
http://ruby-doc.org/core/classes/String.src/M000820.html
or any else as required .

Thanks for ur instant reply Rajeev. On irb strip is working exactly the
way i want but inside code it isn't solving the purpose.

rajeevsharma86 wrote:

Explain yours purpose here

put some lines of code i will tell you the way
do something in model
before_save : strip_description

def strip_description

unless !self.description.nil?

     self.description = self.description.strip # or whatever please check that how to                                                                            # implement strip on string

end

Still having issue rajeevsharma86@gmail.com add me

Hi:

Its a simple form to create a job. FCKeditor has been placed with the
name job[description].
At the create event, it assigns the value to @job.description.
I was trying to strip it before saving like:
@job.description = params[:job][:description].strip, but it isnt solving
the purpose.

In the db, the description field shows a number of blank lines at the
beginning and end.

rajeevsharma86 wrote:

try this
**validate :striped_descriptions
def striped_descriptions

striping_description

unless self.description.nil?
    logger.debug 'self.description before strip'
    logger.debug self.description
    striped_description = (self.description).strip
    self.description = striped_description
    logger.debug 'self.description after strip'
    logger.debug self.description

end
end**
or
try this
**before_save :striped_descriptions
def striped_descriptions

striping_description

unless self.description.nil?
    logger.debug 'self.description before strip'
    logger.debug self.description
    striped_description = (self.description).strip
    self.description = striped_description
    logger.debug 'self.description after strip'
    logger.debug self.description

end
end**

Didnt help.

Hey thanks Rajeev.. It worked..
Was doing a silly mistake..

Priya Saini wrote:

cheers :slight_smile:

Priya Saini wrote:

Hi:

I am using FCKeditor in one of my form, when i copy and paste something
into it using WordPaste, it appends few newlines at the beginning and at
the end.
How can i strip just those \n without effecting the inbetween newlines
and the formatting.

This is probably best done with a regular expression.

TIA,
Priya

Best,

Quoting Marnen Laibow-Koser <lists@ruby-forum.com>:

Priya Saini wrote:
> Hi:
>
> I am using FCKeditor in one of my form, when i copy and paste something
> into it using WordPaste, it appends few newlines at the beginning and at
> the end.
> How can i strip just those \n without effecting the inbetween newlines
> and the formatting.
>

This is probably best done with a regular expression.

Isn't this just what String#strip does?

Jeffrey

Jeffrey L. Taylor wrote:

Quoting Marnen Laibow-Koser <lists@ruby-forum.com>:

This is probably best done with a regular expression.

Isn't this just what String#strip does?

No. Strip removes all whitespace, not just newlines.

Jeffrey

Best,