• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Buffered Writer and For loop

 
Callum Ta
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

I am having problems with my IRC bot coded in Java. I can't for the life of me print out the values stored within token[] to print to a single line.

My program consists of 2 classes, a main class "ircbot" and a class "Bot".

The code i am having problems with is



And the "say" function located in the Bot class is




As you can see, if i were to type !say 1 2 3 4 5 6

The output would be;

1
2
3
4
5
6

How could i print the numbers on the same line?

Thank you
 
Rob Spoor
Sheriff
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't call println but print. println basically calls print followed by printing a line break.
 
Callum Ta
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:Don't call println but print. println basically calls print followed by printing a line break.


Oh sorry, i wasn't referring to the system out

i was referring to the bw.write
 
Rob Spoor
Sheriff
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't add the "\n".
 
Callum Ta
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:Don't add the "\n".


Again, thanks for the reply.

I tried this and the bot doesn't write anything at all to the irc channel.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're splitting the line into tokens, and sending each one with a separate PRIVMSG command. If you don't want the line split into tokens, then just pass the whole line (after the !say, of course) to the say() method. You'll presumably need to modify your regular expression to match the message part of the line as a group, so you can extract just the message.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic