Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Formatting Issue

  1. #1
    Junior Member
    Join Date
    May 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Formatting Issue

    Hello,

    I am using PircBotX to create a irc bot, but I am having an issue creating a dynamic command system. I am using MySQL to store information into a database, and it works fine. I also have no problem reading from the database so please do not even consider that it is the database.

    	public void onMessage(MessageEvent<PircBotX> event) throws Exception {
    		String[] args = event.getMessage().split(" ");
    		if(event.getMessage().startsWith("!peacebot command add")) {			
    			MySQL mysql = new MySQL();
    			mysql.connect("127.0.0.1", "root", "", "peacebot");
    			mysql.Query("INSERT INTO `peacebot`.`peacebot_command` (`command_id`, `command_channel`, `command_trigger`, `command_message`) VALUES (NULL, '" + event.getChannel().getName().replace("#", "") + "', '" + args[3] + "', '" + event.getMessage().substring(22).replaceAll(args[3], "") + "');");
    			mysql.disconnect();
    			/**for(int i = 0; i < args.length; i++) {
    				List<String> list = new ArrayList<String>();
    				for (String s : args) {
    					list.add(s);
    				}
     
    				System.out.println(list);
     
    				Iterator<String> itr = list.iterator();
    		        while(itr.hasNext()){
    		            System.out.println(itr.next());
    		        }
    			}**/
    		}
    	}

    I already know what the problem is, but I do not know how to fix it. The problem is that the argument[3] has a space in it, but it will not erase the space no matter what I do.

    Example:
    1399576848536 <<<:mretech!mretech@mretech.tmi.twitch.tv PRIVMSG #mretech :!peacebot command add !test test
    1399576850794 <<<:mretech!mretech@mretech.tmi.twitch.tv PRIVMSG #mretech :!test
    1399576850818 >>>PRIVMSG #mretech : test


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Formatting Issue

    argument[3] has a space in it, but it will not erase the space
    Can you strip out the code you are using to remove a space from a String and post it here for testing?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    May 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Formatting Issue

    Quote Originally Posted by Norm View Post
    Can you strip out the code you are using to remove a space from a String and post it here for testing?
    Well, all I am doing is removing args[3] from the String the gets put into the command_message column with the replaceAll function but for whatever reason it leaves a space in the String.

    event.getMessage().substring(22).replaceAll(args[3], "")

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Formatting Issue

    Can you make a sample statement with literal values in place of variables?
    The posted code does not show what is in getMessage().substring(22)
    or what is in args[3].
    Their contents are important when determining what the code should do.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Formatting my output
    By chemical_dog in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 7th, 2013, 07:24 PM
  2. String formatting
    By aussiemcgr in forum Java Theory & Questions
    Replies: 5
    Last Post: September 24th, 2013, 10:55 AM
  3. Formatting this number.
    By MR bruto in forum What's Wrong With My Code?
    Replies: 3
    Last Post: June 10th, 2013, 02:08 AM
  4. Gson Formatting
    By techwiz24 in forum Java Theory & Questions
    Replies: 4
    Last Post: October 2nd, 2011, 07:48 PM
  5. Formatting Output
    By mael331 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: September 14th, 2011, 06:41 PM