So I'm at a loss here. What I have is a string that picks up if a user types a certain command. If they don't add an argument at the end, the code block doesn't run. What I need to do is remove the basic command from the string, and storing the user's argument in a separate string. I have attempted using split's but every result I get doesn't have two separate indexes. If I use  instead of  on the split string, i get an ArrayOutOfBoundsException: 1
The result of grabbing the user's input
What I want:
I think you will have to escape the dollar sign, which, I think, is a meta‑character denoting one end of the line or the other. What you are using is a “regular exression”, which you can read about in the Java™ Tutorials. If you get the expression right, you will splt the String into before that and after that, probably a two‑element array with the first being the empty String "".
If you always have the same length introduction, try the substring() method. But you will have problems if there are things like double spaces in the input.
Try a Scanner, calling next() twice followed by nextLine()
A little off topic, but as I'm a beginner at java with basic knowledge, people continuously point me to these documentation websites. However, every time I attempt to learn from there, they use language that is hard to understand except for user's who are more advanced into the subject. I find myself reading the same sentences four or five times over and can't wrap my brain around them. The only reason I've gotten this far was simply by playing around with the program and codecademy.
Anywho, I'll try out your advice and see if it gets anywhere.
Your advice worked. I checked up on the documentation and used the magic of ctrl+f. Exactly like you said. I just used "\\" before the dollar sign, and it split correctly. I appreciate the help.
"If you ain't first, you're last." - Ricky Bobby
posted 3 months ago
Drew Hedgecoke wrote:. . . . I just used "\\" before the dollar sign, and it split correctly.
I appreciate the help.
That's a pleasure I sometimes get it right.
I suggest you replace the middle space in the regular expression by\\s+. You will doubtless know from your reading that \\s+ represents any number > 0 of whitespace characters, which will allow your users to use double spaces. Also consider adding \\s+ at the end of your regular expression, which will strip any leading spaces from the remainder of the text. By the way: lots of people abbreviate “regular expression” to “regex”.
There are three kinds of standard documentation for Java®. One is the API documentation, which is definitive for the specification of the methods, though it is possible that somebody made a mistake writing something. It is written on the assumption shown here that the readers are experienced programmers. The second, which is also definitive, is a specification, the best‑known being the Java® Language Specification, usually called the JLS. Both those contain parts very hard to read, unfortunately. The third is tutorials, this one being provided by Oracle (formerly by Sun), and most tutorials are easy to read. I suggest you should always read the documentation, and then decide which parts you can't understand and need to know about. Quote them here and ask; we shall be only too happy to answer. You will gradually find the bits you understand getting bigger. For example, you now know the difference between the String parameter for this method and the String parameter for this one, and also why the two parameters have different names.
moose poop looks like football shaped elk poop. About the size of this tiny ad:
Download Free Java APIs to Work with Office Files and PDF