This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Buffered Writer and For loop Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Buffered Writer and For loop" Watch "Buffered Writer and For loop" New topic
Author

Buffered Writer and For loop

Callum Ta
Greenhorn

Joined: Apr 23, 2010
Posts: 3
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

Joined: Oct 27, 2005
Posts: 19655
    
  18

Don't call println but print. println basically calls print followed by printing a line break.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Callum Ta
Greenhorn

Joined: Apr 23, 2010
Posts: 3
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

Joined: Oct 27, 2005
Posts: 19655
    
  18

Don't add the "\n".
Callum Ta
Greenhorn

Joined: Apr 23, 2010
Posts: 3
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

Joined: Jul 08, 2003
Posts: 24183
    
  34

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.


[Jess in Action][AskingGoodQuestions]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Buffered Writer and For loop
 
Similar Threads
doubt in indexOf()
Tokenising using String.split().
Tokenizing with regex pattern. Little confused!
String Tokenizer - getting the 10 th Token
Reading csv file.