Thread: Checking Only For One Space

Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1 Checking Only For One Space 
    I'm President Carter


    Join Date
    Jan 2011
    Posts
    1,204
    Thanks given
    17
    Thanks received
    222
    Rep Power
    144
    I was wondering how I would stop the string from checking if there are any spaces after using a space once? I also want to do this without using the substring method because this command incorporates more than just this. If anyone can please help me out with this it would be greatly appreciated.

    Code:
    			String[] arg = playerCommand.split(" ");
    			if (arg.length == 2) {
    				String teleportTo = arg[1];
    				if (PlayerHandler.isPlayerOn(teleportTo)) {
    					for (Player otherPlayer : PlayerHandler.players) {
    						if(otherPlayer != null) {
    							if (otherPlayer.playerName.equalsIgnoreCase(teleportTo)) {
    								player.getPA().movePlayer(otherPlayer.getPosition().getX(), otherPlayer.getPosition().getY(), otherPlayer.getPosition().getZ());
    								player.getActionSender().sendMessage("You successfully teleport to " + Misc.optimizeText(otherPlayer.playerName));
    							}
    						}
    					}
    				} else {
    					player.getActionSender().sendMessage("This player is currently offline.");
    				}
    			}


    Reply With Quote  
     

  2. #2  
    I'm President Carter


    Join Date
    Jan 2011
    Posts
    1,204
    Thanks given
    17
    Thanks received
    222
    Rep Power
    144
    Bump


    Reply With Quote  
     

  3. #3  
    Community Veteran

    mige5's Avatar
    Join Date
    Aug 2008
    Posts
    5,528
    Thanks given
    573
    Thanks received
    1,410
    Rep Power
    2114
    so instead of doing this:
    Code:
    12 34 56
    ---
    arg[0] = 12
    arg[1] = 34
    arg[2] = 56
    you would want it to work like this?
    Code:
    12 34 56
    ---
    arg[0] = 12
    arg[1] = 34 56
    Number of page #1 releases with most views & posts: (Updated: 2023)
    RS2 server section: 1
    RS2 client section: 2
    Reply With Quote  
     

  4. #4  
    I'm President Carter


    Join Date
    Jan 2011
    Posts
    1,204
    Thanks given
    17
    Thanks received
    222
    Rep Power
    144
    Quote Originally Posted by mige5 View Post
    so instead of doing this:
    Code:
    12 34 56
    ---
    arg[0] = 12
    arg[1] = 34
    arg[2] = 56
    you would want it to work like this?
    Code:
    12 34 56
    ---
    arg[0] = 12
    arg[1] = 34 56
    ^Exactly that


    Reply With Quote  
     

  5. #5  
    I'm President Carter


    Join Date
    Jan 2011
    Posts
    1,204
    Thanks given
    17
    Thanks received
    222
    Rep Power
    144
    Bump


    Reply With Quote  
     

  6. #6  
    Registered Member
    Join Date
    Oct 2012
    Posts
    270
    Thanks given
    8
    Thanks received
    20
    Rep Power
    14
    I'm sorry but I don't fulling understand, do you mean it ignores all spaces?
    Reply With Quote  
     

  7. #7  
    Registered Member
    Join Date
    Aug 2008
    Posts
    2,418
    Thanks given
    721
    Thanks received
    595
    Rep Power
    1220
    You'll probably need to use regex for this.
    Reply With Quote  
     

  8. #8  
    Banned

    Join Date
    Mar 2011
    Posts
    4,062
    Thanks given
    194
    Thanks received
    689
    Rep Power
    0
    Ummm...

    arg[3] = arg[1] + arg[2];

    ??
    Reply With Quote  
     

  9. #9  
    Super Donator

    Batukka's Avatar
    Join Date
    Oct 2011
    Posts
    2,433
    Thanks given
    86
    Thanks received
    342
    Rep Power
    496
    indexOf(" ") thats how you check only frist spec.
    Reply With Quote  
     

  10. #10  
    I'm President Carter


    Join Date
    Jan 2011
    Posts
    1,204
    Thanks given
    17
    Thanks received
    222
    Rep Power
    144
    Quote Originally Posted by relex lawl View Post
    Ummm...

    arg[3] = arg[1] + arg[2];

    ??
    That wouldn't work because I'm checking the length of the args first. So its already greater than 2 if I have to add another two together. And I can't change the length of because another part of the command uses the length 3 and 4.


    Reply With Quote  
     

Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Need help with variable checking.
    By Red Bull in forum Help
    Replies: 5
    Last Post: 07-17-2012, 11:45 PM
  2. checking for updates 1%
    By Mr Sandman in forum Help
    Replies: 9
    Last Post: 04-22-2012, 07:32 AM
  3. Checking MySQL
    By Defiled-X in forum Help
    Replies: 0
    Last Post: 03-04-2012, 05:17 AM
  4. Just checking about a UGC.
    By Bells in forum Spam
    Replies: 0
    Last Post: 02-12-2012, 04:48 PM
  5. checking array?
    By luvgirl12345 in forum Help
    Replies: 3
    Last Post: 07-16-2009, 11:07 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •