Results 1 to 2 of 2
- 08-29-2012, 08:56 PM #1
Member
- Join Date
- Aug 2012
- Posts
- 10
- Rep Power
- 0
Help with knowing if .split()[1] exists
I want to do that if somebody types "!say ABC" then it would be able to acess only "ABC" and do whatever to it.
so I have an
, then to get "ABC" I doJava Code:str.indexOf("!say")The problem is that if somebody types only "!say" with nothing that follows, the program crashes due to "out of bounds" or w/e. (because I am trying to access "str.split(" ")[1]" which doesn't exist).Java Code:str.split(" ")[1]
What if statement can I use to check if ".split(" ")[1]" exists?
Thanks
- 08-29-2012, 09:28 PM #2
Re: Help with knowing if .split()[1] exists
Java Code:String[] split = str.split(" "); if(split.length > 1) { // split[1] exists }Get in the habit of using standard Java naming conventions!
Similar Threads
-
call a thread knowing its ID
By cucucur in forum Threads and SynchronizationReplies: 1Last Post: 07-05-2011, 12:14 AM -
Need help in knowing how to clear buffer.
By tedstevens in forum New To JavaReplies: 1Last Post: 08-20-2009, 05:02 AM -
Knowing which IP address is active
By sukatoa in forum NetworkingReplies: 2Last Post: 05-05-2009, 04:01 PM -
How to split a String using split function
By Java Tip in forum java.langReplies: 4Last Post: 04-17-2009, 08:27 PM -
How to split a String using split function
By JavaBean in forum Java TipReplies: 0Last Post: 10-04-2007, 09:32 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks