|
Can you guys help me with the following?
I'm writing a program that asks the user to enter the name of the text file, it then scan the content and extract numbers from that file. The problem is I want it to filter out the non-digit elements using Stream Tokenizer. So with the following text:
I wish I can earn $1,000,000 a year!
The program will return 1000000
Thanks...
|
|
|
|
|
Your problem is that the stream tokenizer isn't going to recognise "," as part of a number. There are two approaches I'd consider.
- Clear the tokenizer, then set 0-9 and , as "word" characters. Ignore every token but words, then, when you get a word, check that there are digits in it amongst the commas.
- Forget the tokenizer, read character by character and write a state based lexical analyser. This needn't be very complicated, the states are just "I'm in a number" and "I'm not in a number".
The lexical analyser would look something like this.
InputStreamReader is ...
boolean isInANumber;
int theNumber;
int ch;
do {
ch = is.read();
if(isInANumber) {
if(Character.isDigit(ch))
theNumber = theNumber * 10 + Character.digit(ch, 10);
else if(ch != ',') {
.... do something with theNumber
isInANumber = false;
}
}
else if(Character.isDigit(ch)) {
isInANumber = true;
theNumber = Character.digit(ch, 10);
}
}
while(ch != -1);
|
|
|
|
|
Assuming u have already tokenized the sentence using
StreamTokenizer st=new StreamTokenizer(ursentence);
while(st.hasMoreElements())
{
String dollarValue=(String)st.nextElement();
if(dollarValue.charAt(0)=='$')
{
String s="";
int i=0;
while(true)
{
if((dollarValue.charAt(i)>='0'&& dollarValue.charAt(i)<='9'))
{
s=s+dollarValue.charAt(i);
}
else if(dollarValue.charAt(i)=='.')
{
s=s+dollarValue.charAt(i);
}
else if(dollarValue.charAt(i)==' ')
{
System.out.println("invalid number format");
System.exit(1);
}
i++;
if(i==dollarValue.length())break;
}
System.out.println("This is ur number"+Integer.parseInt(s));
}
}
I.The above function assumes that there is $ sign at first position of the value and there are no spaces after $ sign.
II.The above program assumes that u r using integers for double values.
If the value is double use Double.parseDouble instead of Integer.parseInt
Cheers
Koundinya
|
|
|
|
|
hi there,
You forgot to include one class file TestObj in XYObjectArray.zip. Otherwise please let me know how can i create that object which you used in ArrayTest program.
thanks
saurabh
|
|
|
|
|
Why I need the UDP ?
i want to create something (Like OCX or DLL) to let the server send a message to the client(s) inform them to refresh ,redirect ,there is new email, XXX is logged on.
how i'm thinking to solve this problem?
create client OCX (without using the WinSock.OCX) to wait and manage the server message. and create an DLL on the server that will send the message to the Client OCX. (i think this is a good solution ?! do you think that ????!! )
What i want ?
i do not know how to write a code deal with UDP ?!
if you have another idea ?? i'll be pleased to you if you send it to me
Note : I’m talking about intranet.
Can any one there help me ? or give and any article(s) that could help ?!
web programmer.
|
|
|
|
|
Hi, I am Yohan. I am thinking of making screen mate using Java swing. But problem is that I couldn't find any solution of hiding jwindow while displying the image only in the desktop when the program launced and that moves when mouse cliked on it , so that I can show visual effects as same as that of scree mates made of C. if anyone know how to hide jwindow but show and move image, please let me know
|
|
|
|
|
I've heard that Microsoft has not planned to implement a higher version of Java than 1.1 in it's Internet Explorer. What programming technique should I use if I want to get the same functionality that I got with Java Applets? (For example common dialog controls; platform independence)
|
|
|
|
|
Well. Users can download Java Runtime plugin's and your Java Applet's should just work fine with the plugin in any browser.
---------------
Dan Ammasai
---------------
|
|
|
|
|
activex controls are an option.
they allow you to run native code inside a web browser, so you can do whatever you want (VB, C++ etc)
they are not secure though, so some peoples security settings may not let them run.
-Jack Mott
jackm@scalablesoftware.com
|
|
|
|
|
hi
Alternative to the older VM hmmm !,
U may use java plugins instead ,
but for that u will have to use
OBJECT tag instead of APPLET tag(internet explorer).
EMBED tag in netscape communicator.
and good thing is u can always download newer vertual machine and configure ur pluggin for that.
Ur HTML would also run swing object provided u configure client plugin for that and use above mentioned tag ..
If u have any further queries ,mail me at pushp_i@hotmail.com and metion 'codeproject' in subject
Pushpi from india
|
|
|
|
|
Hi! I've got a problem. I would like to write Java applets with swing components.
But Microsoft's Internet Explorer is not able to show them. Is there a possiblity to include the swing classes in my project manually so that a user of IE can download this classes together with my project?
If you cannot answer this question. Do you know a discussion place where I may get any help?;)
Thanks.
Gregor Mitsch
E-Mail: abacus-@gmx.de
|
|
|
|
|
Nope,
Dear Gregor, Javaplugins comes into play. Sun had realized that many of the browsers, when release in the market, uses the obsolete JVM. So sun had developed a plugin which means, u uses the latest jvm and it is downloaded from the site automatically when javascript detect that the browser doesnot have a plugin.
U can get more information on how to use plugin from java.sun.com
cheers
dotcomguy
|
|
|
|
|
hi
U may use java plugins instead.
but for that u will have to use
OBJECT tag instead of APPLET tag(internet explorer).
EMBED tag in netscape communicator.
and good thing is u can always download newer vertual machine and configure ur pluggin for that.
Ur HTML would also run swing object provided u configure client plugin for that and use above mentioned tag ..
If u have any further queries ,mail me at pushp_i@hotmail.com and metion 'codeproject' in subject
Pushpi from india
P.S. PATWAL
|
|
|
|
|
I'd like to use swing in an applet too, and I don't think I can use the sun java plugin because of the way this applet interacts with other elements of the Windows system.
Microsoft, predicatably, has it's own user interface routines called AFC which are in com.ms.ui.*. The problem is that I can find no on-line documentation for them. J++ displays the bare class structures for me and I've been using trial and error and a few examples I've turned up but it looks like I'm going to have to buy a book.
They do provide stuff like multi-column scrolling lists, trees etc. and in a microsoft-looking format.
Of coursre this probably means you'll have to do it all again if you want a version of the applet to run anywhere but IE.
|
|
|
|
|
When i try rum this command java XXXXXX
This error was come out :
"Exception in thread "main" java.lang.NoSuchMethodError : main"
Any idea to solve it
|
|
|
|
|
A java program must have a public class whith a method main like in the code below:
public class FirstApp
{
public static void main(String argv) //this function must exist in every program that you want to run
{
//some code here
}
}
When you run java FirstApp type the name with apropriate case(java is case sensitive)
|
|
|
|
|
Hi,
How is Java compared to C++ in what matters to standalone programs ???
Thank You,
Pedro
Pedro
|
|
|
|
|
Hmph.. I think different things matter to different stand alone programs. You're doing graphical interfacing and want portability java's pretty good. If it's all about fast number crunching probably not so good. The class library can save you a lot of work, once you can find your way arround it, of course.
I'd say, typically, development time with Java will be faster but the resulting program, perhaps, not quite as clean. For a start it's slughly icky having to run the interpretter every time.
|
|
|
|
|
|
|
Anybody now how to do Insertion sort in Java ( JDK 1.2 )
|
|
|
|
|
Must it be Insertion sort? Why don't you use Quicksort.
If you want I'll send you my little Quicksort-Wrapper-Class...
E-Mail me...
|
|
|
|
|
It entirely depends how your data is likely to be stored. If you want a dense array there are binary chop search routines supplied in the "Arrays" class (and use System.arrayCopy). You should also take a good look at the TreeMap or TreeSet clases one of which will probably handle it all for you.
|
|
|
|
|
Yesterday I posted a message and thanked David Woods for code supplied here in this forum. David was very kind and pointed me to it.. but the code was written by Davanum Srinivas. Sorry Davanum, and thankyou for sharing your code here, got me over a big hump......
Bob
|
|
|
|
|
I was successful implimenting drag and drop from a JTree to Native NT system, used David Woods code he posted here to give me a leg up, thanks Dave, helped alot. I still need to determine the path the object was dropped into the native system though, and have not found a way to pull it out. Anyone have some suggestions ?
|
|
|
|