# If string = "mike" then print "Hi mike"

**URL:** <https://www.ruby-forum.com/t/if-string-mike-then-print-hi-mike/167260>\
**Category:** Ruby\
**Created:** [May 6, 2009, 3:43am UTC](https://www.ruby-forum.com/t/if-string-mike-then-print-hi-mike/167260 "2009-05-06T03:43:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![i8igmac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/919ad9/32.png) [@i8igmac](https://www.ruby-forum.com/u/i8igmac)\
**Post date:** [May 6, 2009, 3:43am UTC](https://www.ruby-forum.com/t/if-string-mike-then-print-hi-mike/167260/1 "2009-05-06T03:43:16Z")

</div>

server/client connection  
so, im only a few days into ruby, im working on some tcp and there is a  
problem with my client.rb… if str == ??? this if statement is always  
skipped and im not sure why?

also, from the server with the gets command i want to send the client a  
string like “mike skateboard boxing” then when the client recives this  
string how can i brake this into 3 arrays or strings?

#server.rb  
require “socket”  
dts = TCPServer.new(‘localhost’, 1234)  
loop do  
Thread.start(dts.accept) do |s|  
print(s, " is accepted\n")  
#gets, what command to send to the client?  
str = gets  
s.write(str)  
print(s, " is gone\n")  
s.close  
end  
end  
------------end of server-------------

#client.rb  
require ‘socket’  
while true  
streamSock = TCPSocket.new( “127.0.0.1”, 1234 )  
str = streamSock.recv( 100 )  
print str

if str == ‘mike’  
print ‘Hi mike’  
elsif str == ‘user’  
print ‘hi user’  
end  
end

--------end of client

---

<div class="post-metadata">

**Author:** ![i8igmac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/919ad9/32.png) [@i8igmac](https://www.ruby-forum.com/u/i8igmac)\
**Post date:** [May 6, 2009, 4:57am UTC](https://www.ruby-forum.com/t/if-string-mike-then-print-hi-mike/167260/2 "2009-05-06T04:57:33Z")

</div>

Hi,

At Wed, 6 May 2009 10:43:23 +0900,  
Bigmac T. wrote in [ruby-talk:335871]:

> so, im only a few days into ruby, im working on some tcp and there is a  
> problem with my client.rb… if str == ??? this if statement is always  
> skipped and im not sure why?

#gets method returns a string with a newline if you ended the  
input with enter. You can chomp it or use double Ctrl-D  
instead of enter.

---

<div class="post-metadata">

**Author:** ![i8igmac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/919ad9/32.png) [@i8igmac](https://www.ruby-forum.com/u/i8igmac)\
**Post date:** [May 6, 2009, 5:17am UTC](https://www.ruby-forum.com/t/if-string-mike-then-print-hi-mike/167260/3 "2009-05-06T05:17:25Z")

</div>

I’ve gotten into the habit of using gets.chomp when reading input of  
any kind. It’s so easy to forget that newlines are still on there.

---

<div class="post-metadata">

**Author:** ![i8igmac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/919ad9/32.png) [@i8igmac](https://www.ruby-forum.com/u/i8igmac)\
**Post date:** [May 6, 2009, 5:58am UTC](https://www.ruby-forum.com/t/if-string-mike-then-print-hi-mike/167260/4 "2009-05-06T05:58:36Z")

</div>

Nobuyoshi N. wrote:

> Hi,
> 
> At Wed, 6 May 2009 10:43:23 +0900,  
> Bigmac T. wrote in [ruby-talk:335871]:
> 
> > so, im only a few days into ruby, im working on some tcp and there is a  
> > problem with my client.rb… if str == ??? this if statement is always  
> > skipped and im not sure why?
> 
> #gets method returns a string with a newline if you ended the  
> input with enter. You can chomp it or use double Ctrl-D  
> instead of enter.

Oh, wow… a bit confused at first but then i googled ruby chomp and  
then it made sence, when you press enter \n

if string.chomp == “mike”  
print “hello mike\n”  
system(“calc.exe”)

# how can i execute calc.exe and continue with the script well calc is

still running???

---

<div class="post-metadata">

**Author:** ![i8igmac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/919ad9/32.png) [@i8igmac](https://www.ruby-forum.com/u/i8igmac)\
**Post date:** [May 6, 2009, 3:29pm UTC](https://www.ruby-forum.com/t/if-string-mike-then-print-hi-mike/167260/5 "2009-05-06T15:29:39Z")

</div>

Hi,

2009/5/6 Bigmac T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> > input with enter. Â You can chomp it or use double Ctrl-D  
> > still running???

Try  
system(“start calc.exe”)

Regards,  
Park H.
