Add a string end of the line

Hi
i m reading a line from a file

lastresult = File.open(‘regex.tmp’)

which has a output like this

set member “user1” “user2” “user3” “user4” “user5”

Now i need to add another string end of that line so that it become

set member “user1” “user2” “user3” “user4” “user5” “newuser”

i tryed this way

lastresult = File.open(‘regex.tmp’)
#member = lastresult.readline.to_s.chomp << “#{getuser}”
member = lastresult.readline

    concat = "#{member.strip}"
    puts concat + getuser
    myconcat= "#{member.to_s.chomp}" "#{getuser}"
    puts myconcat.strip
    lastresult.close

but the result i am getting

set member “user1” “user2” “user3” “user4” "user5"“newuser”
set member “user1” “user2” “user3” “user4” “user5” “newuser”

one does not have any GAP between "user5"“newuser”

another one is too much GAP

Can any one please help me to get the correct way ??

i need output should be

set member “user1” “user2” “user3” “user4” “user5” “newuser”

thanks

How about:

lastresult = File.open(‘regex.tmp’)
#member = lastresult.readline.to_s.chomp << " #{getuser}"
member = lastresult.readline

    concat = "#{member.strip}"
    puts concat + getuser
    myconcat= "#{member.to_s.chomp}".strip + " #{getuser}"
    puts myconcat.strip
    lastresult.close

thanks for helping me out
its work perfectly

On Thu, 23 Aug 2012 08:20:57 +0900
Fosiul A. [email protected] wrote:

i m reading a line from a file
[… skipped …]
Can any one please help me to get the correct way ??

File.open(‘regexp.tmp’) do |fd|
puts fd.readline.rstrip << " " << getuser.to_s.inspect
end


Sincerely yours,
Aleksey V. Zapparov A.K.A. ixti
FSF Member #7118
Mobile Phone: +34 677 990 688
Homepage: http://www.ixti.net
JID: [email protected]

*Origin: Happy Hacking!

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