views:

19

answers:

1

So stand alone I get what I need. But I want to truncate it, my dynamic text comes out with dirty text globbered with Microsoft Word garbage.

An Example :

≪! [If Gte Mso 9]>≪Xml>  ≪Br /> ≪O:Office Document Settings>  ≪Br /> ≪O:Allow Png/>  ≪Br /> ≪/O:Off...

So how do I get the best of both worlds? Is there a shorthand ruby way to do this? For example a gsub statement that would clip off everything after the 125th char?

+1  A: 

if you just want to slice, you can

>> long_ugly_string = "omg this is a long string"
=> "omg this is a long string"
>> long_ugly_string[10..-1]
=> "s a long string"

Reference: http://ruby-doc.org/core/classes/String.html#M000771

so, you are just specifying the starting character (10) and the ending character (-1 tells it to go to the end of the string).

Geoff Lanotte
I apologize for being daft..but how would you write that? I'm not familiar with regexp. I tried str.slice(125..-1) with no effect
Trip
Hmm I find that string[0..125] works, but its strange in this case, that space is empty chars because its MicrosoftWord. So now i'm looking for a regexp that would make regexp = starting point OR first char and put it in as str[start..0].
Trip
There is also this one: long_ugly_string.gsub(/^.{10}/,'')
Geoff Lanotte