Cropping text strings

Hello,

This statement here can return a very long paragraph
<%=h openjob.ProblemDesc %>

Is there a way to trim it to say the first 50 characters? In VBScript
I would use Left(). (I am working in ruby on rails if that matters)


“Hey brother Christian with your high and mighty errand, Your
actions speak
so loud, I can’t hear a word you’re saying.”

-Greg Graffin (Bad Religion)

Rails also has a helper for this:

http://api.rubyonrails.com/classes/ActionView/Helpers/TextHelper.html#M00061
5

truncate(“Once upon a time in a world far far away”, 14)
=> Once upon a…

HTH,

FElix

openjob.ProblemDesc[0…49] should do the trick.

On 9/17/07, [email protected] [email protected]
wrote:


“Hey brother Christian with your high and mighty errand, Your actions
speak
so loud, I can’t hear a word you’re saying.”

-Greg Graffin (Bad Religion)

On Sep 17, 3:41 pm, Morton G. [email protected] wrote:

<%=h openjob.ProblemDesc %>

Is there a way to trim it to say the first 50 characters? In VBScript
I would use Left(). (I am working in ruby on rails if that matters)

As will the following:

openjob.ProblemDesc.first(50)

Regards, Morton

Thank you it worked great!

On Sep 17, 2007, at 3:20 PM, Glen H. wrote:

Is there a way to trim it to say the first 50 characters? In VBScript
I would use Left(). (I am working in ruby on rails if that matters)

As will the following:

openjob.ProblemDesc.first(50)

Regards, Morton

On 9/17/07, Daniel DeLorme [email protected] wrote:

Glen H. wrote:

openjob.ProblemDesc[0…49] should do the trick.

Hate to be anal, but that would return the first 50 bytes, not
characters.

Daniel

Good point, I wasn’t thinking in Unicode.


“Hey brother Christian with your high and mighty errand, Your actions
speak
so loud, I can’t hear a word you’re saying.”

-Greg Graffin (Bad Religion)

Glen H. wrote:

openjob.ProblemDesc[0…49] should do the trick.

Hate to be anal, but that would return the first 50 bytes, not
characters.

Daniel

From: Glen H. [mailto:[email protected]]

On 9/17/07, Daniel DeLorme [email protected] wrote:

> Hate to be anal, but that would return the first 50 bytes, not

> characters.

Good point, I wasn’t thinking in Unicode.

ruby1.9 http://eigenclass.org/hiki.rb?Changes+in+Ruby+1.9#l104

Hi,

Am Dienstag, 18. Sep 2007, 04:41:14 +0900 schrieb Morton G.:

On Sep 17, 2007, at 3:20 PM, Glen H. wrote:

Is there a way to trim it to say the first 50 characters?

As will the following:

openjob.ProblemDesc.first(50)

Cool. Here are two other ones:

openjob.ProblemDesc[ 0, 50]
openjob.ProblemDesc[ /.{50}/u]

Bertram

On 9/18/07, Peña, Botp [email protected] wrote:

From: Glen H. [mailto:[email protected]]

On 9/17/07, Daniel DeLorme [email protected] wrote:

> Hate to be anal, but that would return the first 50 bytes, not

> characters.

Good point, I wasn’t thinking in Unicode.

ruby1.9 http://eigenclass.org/hiki.rb?Changes+in+Ruby+1.9#l104

Nice! I won’t have to think in Unicode :wink:


“Hey brother Christian with your high and mighty errand, Your actions
speak
so loud, I can’t hear a word you’re saying.”

-Greg Graffin (Bad Religion)