Prev: running memprof on ree 2010.02, gives a segmentation fault
Next: Iteration through File.file? misses entries for which File.file?(entry) == true
From: Brian Candler on 2 Aug 2010 05:13 Lucky Nl wrote: > Hi > I Need small help that how to remove leading tags > My text is: > str = "<p>Welcome to ruby </p> <p> </p>" > I want result is > str = "<p>Welcome to ruby</p>" > > Can anybody help You mean trailing, rather than leading? You probably want String#gsub or String#gsub!. For example: $ irb --simple-prompt >> str = "<p>Welcome to ruby </p> <p> </p>" => "<p>Welcome to ruby </p> <p> </p>" >> str.gsub!(/( |\s)+/, " ") => "<p>Welcome to ruby </p> <p> </p>" >> Removing empty paragraphs is left as an exercise. For more information on String and Regexp see http://www.ruby-doc.org/docs/ProgrammingRuby/ However for anything other than the most basic transformations, you are almost certainly better off with a HTML parser like Nokogiri, than chomping HTML with regexps. -- Posted via http://www.ruby-forum.com/.
From: Lucky Nl on 2 Aug 2010 07:22 Hi , Am entering multiple paragrpahs in editior .that will be saved into str varable. Ex: str is <p>test one </p><p> </p><p>test one test onetest onetest one</p> <p>test two test two test two test two </p> <p> </p> we have enetered like this way I want result is <p>test one </p><p> </p><p>test one test onetest onetest one</p> <p>test two test two test two test two</p> here removed end of the nbsptags between paragparhs and removed nbsp; 's in "<p>test two test two test two test two</p>" -- Posted via http://www.ruby-forum.com/.
From: Brian Candler on 2 Aug 2010 08:30 Lucky Nl wrote: > Hi , > Am entering multiple paragrpahs in editior .that will be saved into str > varable. > > Ex: > str is > <p>test one </p><p> </p><p>test one test > onetest onetest one</p> <p>test two test > two test two test two </p> <p> </p> > > we have enetered like this way > I want result is > > <p>test one </p><p> </p><p>test one test > onetest onetest one</p> <p>test two test > two test two test two</p> > > > here removed end of the nbsptags between paragparhs and removed nbsp; 's > in "<p>test two test > two test two test two</p>" Your requirement is unclear. Are you saying you want to remove the 's within the fourth paragraph only, and remove the fifth paragraph entirely? I've shown you how to use gsub, and where to find more documentation on it. String#scan might be useful too. I suggest you use them in whatever way you need, since only you understand what you're trying to achieve. -- Posted via http://www.ruby-forum.com/.
From: MrZombie on 2 Aug 2010 11:12 On 2010-08-02 07:22:33 -0400, Lucky Nl said: > <p>test one </p><p> </p><p>test one test > onetest onetest one</p> <p>test two test > two test two test two </p> <p> </p> str = str.gsub(/ /,"").gsub(/<p>\s*<\/p>/,"") This will remove any from your html, and after that, remove any <p> tag that contained only whitespace character. It's less than optimal, as you could combine it in one go, probably, but I don't want to spend time on stuff you should be able to do on your own. -- Thank you for your brain. -MrZombie
From: Lucky Nl on 3 Aug 2010 02:17
Hi , Let me explain my requiremnt clearly. Am usinng fck editor in rubyonrails. So I can enter data is multiple paragraphs or single paragraph. but after the last paragraph if there is any spaces , i want to remove them |