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 .

On Thu, Aug 19, 2010 at 9:59 AM, Priya S. [email protected]
wrote:

Priya
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.


Thanks:
Rajeev sharma

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:

you may use strip

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

On Thu, Aug 19, 2010 at 9:59 AM, Priya S. [email protected]
wrote:

Priya
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.


Thanks:
Rajeev sharma

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:

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 [email protected] add me

On Thu, Aug 19, 2010 at 10:22 AM, Priya S. [email protected]
wrote:

wrote:
Rajeev sharma
.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.


Thanks:
Rajeev sharma

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 [email protected] add me

On Thu, Aug 19, 2010 at 10:22 AM, Priya S. [email protected]
wrote:

wrote:
Rajeev sharma
.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.


Thanks:
Rajeev sharma

Didnt help.

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

Priya S. wrote:

Didnt help.

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
*

On Thu, Aug 19, 2010 at 10:38 AM, Priya S. [email protected]
wrote:

beginning and end.

unless !self.description.nil?

Thanks:
[email protected][email protected]
.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.


Thanks:
Rajeev sharma

cheers :slight_smile:

On Thu, Aug 19, 2010 at 11:47 AM, Priya S. [email protected]
wrote:

You received this message because you are subscribed to the Google G.
“Ruby on Rails: Talk” group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected][email protected]
.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.


Thanks:
Rajeev sharma

Priya S. 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,
–Â
Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Sent from my iPhone

Jeffrey L. Taylor wrote:

Quoting Marnen Laibow-Koser [email protected]:

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,
–Â
Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Sent from my iPhone

Quoting Marnen Laibow-Koser [email protected]:

This is probably best done with a regular expression.

Isn’t this just what String#strip does?

Jeffrey

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs