File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes String processing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String processing" Watch "String processing" New topic
Author

String processing

Eden Landau
Ranch Hand

Joined: Aug 14, 2011
Posts: 40

Hello

I want to write a method, that when presented with a String, will be able to do the following:
1. Remember from where it was sent (arguments?).
2. Be able to translate the data to an integer and send it back to the appropriate integer back from where it was sent.
3. Be able to enter console mode, where the user will be able to enter, for example, "run method_name" and it'll run it, while being dynamic.

What's the most efficient way of doing that?

Thanks in advance
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11311
    
  16

1) what do you mean by 'remember from where it was sent'? if you use plain old method calls, that happens automatically. when your method returns, it sends its return value back to the calling method.

2) Did you look at the API for the Integer class? perhaps there is a method there that could help...

3) what do you mean by 'enter console mode'? do you just want to write a GUI that does this? what do you mean by 'being dynamic'? if you have a predefined list of methods, it should be straightforward. however, if you want it to be able to pick up new methods on the fly, you have a lot tougher row to hoe...


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Eden Landau
Ranch Hand

Joined: Aug 14, 2011
Posts: 40

1. Method calls? Afraid I didn't quite understand that return thingie at all. I used 'void' methods for that reason.
What I meant was, that that String processing engine will run every time text is entered from the user.
Some of the time, it should convert that text to an integer, and then set it as an integer in the method it was running from.
Clearer?

2. Read the first one. ^_^

3. Console mode was an example. I want the final result to have console like features.
For example, to be able to write "run addNumbers( 4, 6 )" anywhere with text input options, and it'll do that.
By dynamic, I meant that instead of using a predefined list of methods, like you said, it won't matter what comes after the 'run' (again, example), the program'll run that method.

Hope it's clearer now.
Unnar Björnsson
Ranch Hand

Joined: Apr 30, 2005
Posts: 164
I'm afraid that the information you have given us is too vague for us to help you, can you be more specific?
It sounds like you want to write some kind of a shell that accepts string inputs and returns some value, which is quite possible.
Familiarize yourself with the Scanner class and String class.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Eden Landau wrote:For example, to be able to write "run addNumbers( 4, 6 )" anywhere with text input options, and it'll do that.
By dynamic, I meant that instead of using a predefined list of methods, like you said, it won't matter what comes after the 'run' (again, example), the program'll run that method.


Oh dear. You hardly understand the first thing about Java, but you want to write an expression evaluator.

Well, you aren't going to get that done by asking questions on a forum. It's like showing up on the Home Construction forum and saying "I want to build a condo development. I didn't quite understand that screwdriver thingie, but anyway what should I do?"

In other words what you should do is, if you want to write this expression evaluator, you should start by learning Java to a reasonable standard. Go through the Java tutorials, or get a book which you can go through.
Eden Landau
Ranch Hand

Joined: Aug 14, 2011
Posts: 40

Okay, thanks!
I am, actually, reading a book, and am in that advanced String chapter, but I was writing this program as a practice project some 3 chapters ago, and was wanting to upgrade it.
Oh well...
Unnar Björnsson
Ranch Hand

Joined: Apr 30, 2005
Posts: 164
1. Method calls? Afraid I didn't quite understand that return thingie at all. I used 'void' methods for that reason.

Methods either return some result or they don't, the latter case is a void method. If a method calculates some numbers you want it to return a value in that case you put 'int' instead of 'void' in the method declaration (it returns an int) in which case the method must have a return statement.

Here is an example:


Now we use the method:

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Eden Landau wrote:I am, actually, reading a book, and am in that advanced String chapter...


Well, carry on with that. Code which can recognize and execute other Java code is not just advanced string processing, there's a very large infrastructure required to produce that sort of thing.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38793
    
  23
It's something which other languages support, but in Java™ a method is not a first-class object, so it is very awkward to pass methods like that.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String processing