[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

how to concatenate all the lines into one string

Li Chen

10/8/2006 6:37:00 PM

Hi all,

I am new to Ruby. I just wonder how I can concatenate all the lines from
one file and let them become one string.

Thanks,

Li


--
Posted via http://www.ruby-....

6 Answers

David Vallner

10/8/2006 6:44:00 PM

0

Li Chen wrote:
> I am new to Ruby. I just wonder how I can concatenate all the lines from
> one file and let them become one string.
>

File.read("/path/to/file")

David Vallner

Thomas Adam

10/8/2006 6:45:00 PM

0

On Mon, Oct 09, 2006 at 03:36:43AM +0900, Li Chen wrote:
> Hi all,
> I am new to Ruby. I just wonder how I can concatenate all the lines from
> one file and let them become one string.

How about:

a=File.open("/home/n6tadam/.xsession").read.gsub!('\n', ' ')

I've substituted the newlines for spaces -- but you can do whatever you
want with it.

-- Thomas Adam

--
"If I were a witch's hat, sitting on her head like a paraffin stove, I'd
fly away and be a bat." -- Incredible String Band.

Marc Heiler

10/8/2006 6:49:00 PM

0

Or maybe

File.readlines("xorg.conf").join(' ').gsub!("\n",' ')

--
Posted via http://www.ruby-....

Peter T

1/7/2009 6:08:00 PM

0

> is located in a class and I am calling it
> from the very same userform ...

I don't quite follow but if the code is not in the class/userform that
contains the procedures, change 'Me' to an object reference that refers to
the class, eg

CallByName cls, sProc, VbMethod
where 'cls' refers to the class that contains the proc's

However if you are calling in the same class or userform as the procuderes,
indeed use the 'Me' keyword to refer to the class/userform
CallByName Me, sProc, VbMethod

Regards,
Peter T

PS yes, use the CallByName method if you need to call procedures in class or
userform, App.Run method wouldn't work

"Carim" <carim007@yahoo.com> wrote in message
news:383f777c-d594-4001-98bc-cfc1d23b415c@w39g2000prb.googlegroups.com...
> Peter,
>
> As a matter of fact, the procedure : Private Sub ButtonGroup_Click()
> is located in a class and I am calling it
> from the very same userform ...
> and in one instance, it has to call itself i.e. a CommandButton Click
> will trigger automatically the next
> CommandButton Click ...
> Should I use your recommendation :
> sProc = "CommandButton" & i & "_Click"
> CallByName Me, sProc, VbMethod
>
> Thanks again for your precious help
> Cheers
> Carim


Peter T

1/7/2009 6:39:00 PM

0

Again I don't quite follow, is both "CommandButton" & z & "_Click" and the
CallByName code located in Class1. If so the code you posted should work,
assuming a Public procedure named
"CommandButton" & z & "_Click"
exists in the class

If you are trying to call ButtonGroup_Click, why not simply
Me.ButtonGroup_Click
or
cls.ButtonGroup_Click

See "CallByName" in help.

Regards,
Peter T

"Carim" <carim007@yahoo.com> wrote in message
news:41a1e2be-edb1-4f15-883b-0c1da762b946@l33g2000pri.googlegroups.com...
> Peter,
>
> Again you are right ... there is only one procedure
> named Public Sub ButtonGroup_Click()
> located in the class ( Class1 )
> and the last instruction :
> CallByName Me, "CommandButton" & z & "_Click", VbMethod
> triggers a run-time error 438 ...
> ...
> Thanks again for your help
> Carim
>


Peter T

1/7/2009 7:48:00 PM

0

If I follow, ButtonGroup_Click() is in Class1 and Command#_Click() is in a
Userform, seems like a strange setup.

When you create Class1 pass a reference of the form, eg

assuming you are creating the class from within the form

' in the form, say in the initialize event
Set c = New Class1
Set c.propFrm = Me
c.aa

' in class1
Private moFrm As Object ' top of module

Public Property Set propFrm(oFrm As Object)
Set moFrm = frm
End Property

Public Sub ButtonGroup_Click()

CallByName moFrm, "CommandButton" & z & "_Click", VbMethod
End Sub

If the reference that store the class is not maintained in the userform, the
class needs to be destroyed before unloading the form, or rather in
particular 'moFrm' needs to be released.

It's difficult to understand what you have overall, but I suspect you might
be better trapping all your button events in a WithEvents class. That means
you only need write the Click event once for all your buttons.

Regards,
Peter T







"Carim" <carim007@yahoo.com> wrote in message
news:5e3d08b6-0bd0-410a-80d5-e18d33a5554f@r36g2000prf.googlegroups.com...
> Peter,
>
> May I step back a little bit to let you know briefly about the
> context ...
> A Userform with 20 CommandButtons, which are all managed by a single
> procedure :
> Public Sub ButtonGroup_Click()
> This procedure is located in the single class : Class1
> Everything works fine but the very last instruction for a given random
> CommandButton which has to act as if the user had clicked himself on a
> another CommandButton ...
> Hence, this loop I am trying to achieve ...whereby the procedure calls
> back itself ...
> Hope my explanation is clear enough ...
> Cheers
> Carim