2 Replies - 2775 Views - Last Post: 13 July 2012 - 08:41 AM Rate Topic: -----

#1 lnc12  Icon User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 268
  • Joined: 21-May 08

Change part of string between to tags

Posted 13 July 2012 - 07:57 AM

I have a lot of strings similar to this: rofl rofl rofl rofl <title>Debian</title> rofl rofl rofl rofl
And some times with more tags in same string
Which I need to convert in to thi: rofl rofl rofl rofl ====== Debian ====== rofl rofl rofl rofl

I have the following so far:
puts = "Enter path to input file" 
inputFile = gets.chomp

File.open(inputeFile).each_line{
  |s| checkString(S)
}
def checkString(argument)
    if(argument =~ /.*<.*>.*<.*>.*/)
      replaceString(argument)    
    else
       return argument
    end
end

def replaceString(argument)
  
end



Do people have any ide ?

Is This A Good Question/Topic? 0
  • +

Replies To: Change part of string between to tags

#2 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2086
  • View blog
  • Posts: 3,173
  • Joined: 21-June 11

Re: Change part of string between to tags

Posted 13 July 2012 - 08:24 AM

If you want to be able to handle more complicated cases with nested tags and everything, you'll probably want to use a proper html parser instead of regular expressions.

But if all you need is to replace title-tags with =====, you can just use gsub to replace <title> and </title> with "======".
Was This Post Helpful? 2
  • +
  • -

#3 lnc12  Icon User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 268
  • Joined: 21-May 08

Re: Change part of string between to tags

Posted 13 July 2012 - 08:41 AM

Okay thanks :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1