uhm.. yet another regex/c# question:
I have a html page and want to extract some information from it, like
<span class="time">34 min</span>
I want to extract the 34 as an int (or float or whatever it is)
as regex for that I am using
string timematch = "<span class =\"time\">(.*?) min</span>"
shouldn't this extract the number?
edit: strike all that, it does.. I forgot to use the proper match group!
I'd recommend changing the match to (\d+) if you're looking just for integers, or (\d+(\.\d*)) or such for floats, depending on what exactly is acceptable.
A little bit of detail in your regex can save you a lot of confusion and debugging later down the road, when it unexpectedly starts gobbling up things you didn't want or ever expect it to.
Anyone want to shed some light why I'm getting a read access violation in a C# program that doesn't use pointers ever? I'm using a function I've used a bunch of times and it goes through, does what it's supposed to do, the program keeps going, but as soon as I pass over to a new form the app crashes with an exception. As soon as I comment out the function call (Which does nothing to the new form), it works fine.
For example:
this.Hide();
//commenting this line causes the crash to go away
User aUser = User.GetUserByUsername("bowen");
int val = 3;
MyForm theForm = new Form(val);
theForm.Show();
this.Close();
that form is defined like this, which I'm thinking is part of the problem:
//EDIT: This is for the webbrowser control on the form
//but this part worked fine before I made that function call
[PermissionSet(SecurityAction.Demand, Name="FullTrust")]
[System.Runtime.InteropServices.ComVisibleAttribute(true)]
public partial class MyForm: Form { //... }
I have no idea why commenting out my user function has any bearing on it whatsoever, I'm at a loss. Any ideas?
bowen on
not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
is anybody familiar with the gridworld/critter class assignments in introductory computer science classes?
the idea is to create a critter class (using java) that implements an interface called Critter.
the assignment is to create several different "critters", and define how they move, as specified by the assignment.
for instance, a turtle critter is suppose to move 5 spaces south, 5 spaces west, 5 north, 5 east, and then repeat. the loop functionality comes from the class being accessed by another class - probably a driver class or a step below it.
movements works by returning an integer (assigned to a direction, e.g: return NORTH, where NORTH = -11) from a function called getMove, and the program then moves the critter across the grid.
now, i figured out what i feel is an assbackwards way of doing it, and while it works, i feel that perhaps i'm missing the entire point of the OOP aspect of this assignment. currently i just have like 9 different if statements which lets me define exactly which direction to return.
anybody familiar with this type of work? i feel like i'm overthinking it and doing 10x more work than necessary.
Xenocide Geek on
i wanted love, i needed love
most of all, most of all
someone said true love was dead
but i'm bound to fall
bound to fall for you
oh what can i do
Critter is the fundamental super class. Everything derives and interfaces through the critter class. You're probably doing it exactly how it's supposed to be done.
Edit:
From my limited experience with Java, the OOP designs it forces on you is terrible, so, that may be the part that's ultimately confusing you.
bowen on
not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
Just today I had to write a complicated routine that could fail at any of ten points, each point depending on the results of the previous, and in the event of failure a rollback should be attempted (which could also fail at any point).
How the hell are you supposed to do this without goto? Fucking elitist assholes. What I ended up with was a horribly confusing rat's nest of if/else's that's way uglier than if I could have just used goto to jump out of the main path for error handling.
I'm sure there's a nicely curly-braced way to do this that will make me feel silly.
Just today I had to write a complicated routine that could fail at any of ten points, each point depending on the results of the previous, and in the event of failure a rollback should be attempted (which could also fail at any point).
How the hell are you supposed to do this without goto? Fucking elitist assholes. What I ended up with was a horribly confusing rat's nest of if/else's that's way uglier than if I could have just used goto to jump out of the main path for error handling.
I'm sure there's a nicely curly-braced way to do this that will make me feel silly.
I remember my instructor back in the day told us that a switch/try/catch/throw solution works well for this.
Now you can't move across different functions and parts of code, but, you can do it within one method at least.
bowen on
not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
Basically get Eclipse to run Tomcat. The problem is that I have NO IDEA what the workbench is. Which is #4 on that list. Can anyone point me in the right direction?
The workbench is the "Eclipse" application. The server tab is only in the EE version of Eclipse I think. It should be at the bottom with the console, javadoc, etc tabs.
bowen on
not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
Just today I had to write a complicated routine that could fail at any of ten points, each point depending on the results of the previous, and in the event of failure a rollback should be attempted (which could also fail at any point).
How the hell are you supposed to do this without goto? Fucking elitist assholes. What I ended up with was a horribly confusing rat's nest of if/else's that's way uglier than if I could have just used goto to jump out of the main path for error handling.
I'm sure there's a nicely curly-braced way to do this that will make me feel silly.
The manageable way is probably to organize things in try/catch blocks, remember that you can throw your own exceptions which is effectively a goto if it's all in your function scope.
It is highly idiosyncratic but it does what I need it to do in terms of class diagrams and the like. It has a very command line feel to it despite also being drag and drop.
Thanks, UMLet seems pretty useful.
kedinik on
I made a game! Hotline Maui. Requires mouse and keyboard.
It is highly idiosyncratic but it does what I need it to do in terms of class diagrams and the like. It has a very command line feel to it despite also being drag and drop.
Thanks, UMLet seems pretty useful.
It doesn't want to run for me. Keeps claiming Java isn't installed (or found); other java-based programs work, and Java is both installed and in the usual area - C:\Program Files (x86)\Java.
Okay... So how the hell do I get the Server option to show up on Eclipse??? I have Eclipse EE installed. I have JRE6... Up above I got it to work on the computer labs at school, but now I can't get it to work on my computer at home.
It is highly idiosyncratic but it does what I need it to do in terms of class diagrams and the like. It has a very command line feel to it despite also being drag and drop.
Thanks, UMLet seems pretty useful.
It doesn't want to run for me. Keeps claiming Java isn't installed (or found); other java-based programs work, and Java is both installed and in the usual area - C:\Program Files (x86)\Java.
Did the same thing for me, just running the .jar instead of the .exe works fine though.
It is highly idiosyncratic but it does what I need it to do in terms of class diagrams and the like. It has a very command line feel to it despite also being drag and drop.
Thanks, UMLet seems pretty useful.
It doesn't want to run for me. Keeps claiming Java isn't installed (or found); other java-based programs work, and Java is both installed and in the usual area - C:\Program Files (x86)\Java.
Did the same thing for me, just running the .jar instead of the .exe works fine though.
I install in C:\Java since the program files path seems to confuse some programs. It's usually either that or incorrect environment variables.
Infidel on
0
Options
HalibutPassion FishSwimming in obscurity.Registered Userregular
Just today I had to write a complicated routine that could fail at any of ten points, each point depending on the results of the previous, and in the event of failure a rollback should be attempted (which could also fail at any point).
How the hell are you supposed to do this without goto? Fucking elitist assholes. What I ended up with was a horribly confusing rat's nest of if/else's that's way uglier than if I could have just used goto to jump out of the main path for error handling.
I'm sure there's a nicely curly-braced way to do this that will make me feel silly.
I'm sure others have answered this, but this is how you do it in Java:
void doSomethingInATransaction(){
Transaction tx = new Transaction();
try{
//Do stuff here. If something fails, throw an exception
//We will only get to this point if we haven't thrown an exception
tx.commit();
}
catch(Exception ex){
try{
//We will only get here if an exception was thrown, so rollback the transaction
tx.rollback();
}
catch(Exception ex2){
//do something if the rollback failed
}
}
}
I haven't compiled that code, but that's the basic idea. The exception handling mechanism is analogous to goto in that it immediately stops execution at the current location and jumps to a predefined location in code (the catch block) if an exception is thrown.
Halibut on
0
Options
Monkey Ball WarriorA collection of mediocre hatsSeattle, WARegistered Userregular
edited October 2010
Yeh, I can see how using switch/case and removing the typical break; from the end of the cases would be a good substitute for goto.
But then again I haven't actually used goto since I was doing BASIC back in the 90's.
It is telling that I now think of goto as a poor man's exception.
Monkey Ball Warrior on
"I resent the entire notion of a body as an ante and then raise you a generalized dissatisfaction with physicality itself" -- Tycho
I guess I sort of get what is being said, at least how exceptions relate to the basic routine where every failure point should simply end the whole thing and print an error message or something, since by using exceptions you can move as much error handling as possible out of the main path in much the same was as you would with a goto.
However, what would you guys say if I have to call a bunch of methods that depend on each other, all of which throw the same kind of exception on failure, and I need to know exactly where the point of failure is so rollback actions may be taken? This pretty much forces exception handling or error checking on a line-by-line basis, which gets hella ugly using try catch for every little thing.
Also, one big problem is the home-grown libraries I am working with don't report errors using exceptions, but by return value. So it forces you to very explicitly deal with the error when you write the method call.
On the other hand, sometimes you just want to do one thing and don't give a shit if it fails and writing a whole try/catch for that is just a huge PITA, and frequently it's unclear to me how much of the routine should be in the try block.
LoneIgadzra on
0
Options
The AnonymousUh, uh, uhhhhhh...Uh, uh.Registered Userregular
edited October 2010
Blah blah blah new thread blah blah. If you want to talk, do it in there.
Critter is the fundamental super class. Everything derives and interfaces through the critter class. You're probably doing it exactly how it's supposed to be done.
Edit:
From my limited experience with Java, the OOP designs it forces on you is terrible, so, that may be the part that's ultimately confusing you.
a
switch (1) {
}
then using break as your goto statement is an ugly workaround. you may have to set flags depending if its a windup/unwinding.
Posts
PDFSharp
I have a html page and want to extract some information from it, like I want to extract the 34 as an int (or float or whatever it is)
as regex for that I am using shouldn't this extract the number?
edit: strike all that, it does.. I forgot to use the proper match group!
I'd recommend changing the match to (\d+) if you're looking just for integers, or (\d+(\.\d*)) or such for floats, depending on what exactly is acceptable.
A little bit of detail in your regex can save you a lot of confusion and debugging later down the road, when it unexpectedly starts gobbling up things you didn't want or ever expect it to.
In the minutes field on a webpage? But yeah, as I said, pick a format that matches what you want instead of always using .*
For example:
that form is defined like this, which I'm thinking is part of the problem:
I have no idea why commenting out my user function has any bearing on it whatsoever, I'm at a loss. Any ideas?
It could happen if fractions of a minute are allowed.
I love this problem because it can make other programs crash!
the idea is to create a critter class (using java) that implements an interface called Critter.
the assignment is to create several different "critters", and define how they move, as specified by the assignment.
for instance, a turtle critter is suppose to move 5 spaces south, 5 spaces west, 5 north, 5 east, and then repeat. the loop functionality comes from the class being accessed by another class - probably a driver class or a step below it.
movements works by returning an integer (assigned to a direction, e.g: return NORTH, where NORTH = -11) from a function called getMove, and the program then moves the critter across the grid.
now, i figured out what i feel is an assbackwards way of doing it, and while it works, i feel that perhaps i'm missing the entire point of the OOP aspect of this assignment. currently i just have like 9 different if statements which lets me define exactly which direction to return.
anybody familiar with this type of work? i feel like i'm overthinking it and doing 10x more work than necessary.
most of all, most of all
someone said true love was dead
but i'm bound to fall
bound to fall for you
oh what can i do
Critter is the fundamental super class. Everything derives and interfaces through the critter class. You're probably doing it exactly how it's supposed to be done.
Edit:
From my limited experience with Java, the OOP designs it forces on you is terrible, so, that may be the part that's ultimately confusing you.
Just today I had to write a complicated routine that could fail at any of ten points, each point depending on the results of the previous, and in the event of failure a rollback should be attempted (which could also fail at any point).
How the hell are you supposed to do this without goto? Fucking elitist assholes. What I ended up with was a horribly confusing rat's nest of if/else's that's way uglier than if I could have just used goto to jump out of the main path for error handling.
I'm sure there's a nicely curly-braced way to do this that will make me feel silly.
I remember my instructor back in the day told us that a switch/try/catch/throw solution works well for this.
Now you can't move across different functions and parts of code, but, you can do it within one method at least.
http://www.coreservlets.com/Apache-Tomcat-Tutorial/
Basically get Eclipse to run Tomcat. The problem is that I have NO IDEA what the workbench is. Which is #4 on that list. Can anyone point me in the right direction?
The manageable way is probably to organize things in try/catch blocks, remember that you can throw your own exceptions which is effectively a goto if it's all in your function scope.
Thanks, UMLet seems pretty useful.
It doesn't want to run for me. Keeps claiming Java isn't installed (or found); other java-based programs work, and Java is both installed and in the usual area - C:\Program Files (x86)\Java.
Fucking Eclipse.
e: Found it. I'm an idiot......
Did the same thing for me, just running the .jar instead of the .exe works fine though.
I install in C:\Java since the program files path seems to confuse some programs. It's usually either that or incorrect environment variables.
I'm sure others have answered this, but this is how you do it in Java:
I haven't compiled that code, but that's the basic idea. The exception handling mechanism is analogous to goto in that it immediately stops execution at the current location and jumps to a predefined location in code (the catch block) if an exception is thrown.
But then again I haven't actually used goto since I was doing BASIC back in the 90's.
It is telling that I now think of goto as a poor man's exception.
However, what would you guys say if I have to call a bunch of methods that depend on each other, all of which throw the same kind of exception on failure, and I need to know exactly where the point of failure is so rollback actions may be taken? This pretty much forces exception handling or error checking on a line-by-line basis, which gets hella ugly using try catch for every little thing.
Also, one big problem is the home-grown libraries I am working with don't report errors using exceptions, but by return value. So it forces you to very explicitly deal with the error when you write the method call.
On the other hand, sometimes you just want to do one thing and don't give a shit if it fails and writing a whole try/catch for that is just a huge PITA, and frequently it's unclear to me how much of the routine should be in the try block.
a
switch (1) {
}
then using break as your goto statement is an ugly workaround. you may have to set flags depending if its a windup/unwinding.
Joe's Stream.