Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!

Srikanth Madasu

Ranch Hand
+ Follow
since Sep 10, 2008
Srikanth likes ...
Hibernate Eclipse IDE Spring
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Srikanth Madasu

Then I suppose there is no way I can do it using regex.

I think I can come up with my own parser. First splitting the string on first space. and then apply split on quote followed by space.

Do you think of any other elegant way to do it?

And thanks for your time!
3 years ago
I have a String with pattern KEYWORD ARG1="x" ARG2="test test" that I need to tokenize. I tried using  Pattern. It gives first 2 groups and gives exception after that. Any help is appreciated. Thanks.

 


I get this output:

true
CLICK
name="a"
Exception in thread "main" java.lang.IndexOutOfBoundsException: No group 3
at java.util.regex.Matcher.group(Matcher.java:481)
at com.fepoc.fepdirect.shakeout.main.util.CommandParser.parseCommand(CommandParser.java:43)
at com.fepoc.fepdirect.shakeout.main.util.CommandParser.main(CommandParser.java:32)

3 years ago
Thanks Henry.

It worked. Just changed pattern to include reluctant quantifier "?" .

Thanks!
8 years ago

Campbell Ritchie wrote:Nice touch, using max and min rather than number literals. You do realise that formula will never produce 50 as a result, only 49?



Yes. And if you want to include 50 change the code to this..
int num = rand.nextInt(max-min+1) + min;
8 years ago
First generate a random number and then map it to your range. If you want between 10 and 50
Random rand = new Random();
int min=10,max=50;
int num = rand.nextInt(max-min) + min;

Hope this helps!
8 years ago
Hi all,
I am writing a program to delete all the comments from a given java file.

I was able to remove the single line comments using pattern - Pattern p= Pattern.compile("//(.)*");

But matching multiline comments is getting trickier.
I am using - Pattern p= Pattern.compile("/\\*.*\\*/", Pattern.DOTALL); - Basically match anything between /* and */ and include new lines.

But If I have something like below, it is matching this entire thing as a single match and I am losing the code between the comments.
/**
*comment1
*/
codeline1
line2
/**
*comment2
*/

Could some one help me how to rewrite this pattern so that I dont delete the code between the comments?

Thanks in advance.
8 years ago
Your class is already under the package - hsbookdemo and you already had that in the very first line of your class. so you don't need the second package.

And regarding your question to create new package in IDE just right click on your project name and select new package.

Hope this helps!
9 years ago
I know this is late.. but do you still have place for me on your team? If So let me know what I need to do to get started!

Thanks in advance!
9 years ago
That worked.. Thanks much!
9 years ago
Error is on line 30 where I format the obj...

d.format(c);

9 years ago
I have a requirement of converting times in different time zones to PST.

example if I give "03:30 AM CST" my method should return time in PST.



but its throwing following error:

Exception in thread "main" java.lang.IllegalArgumentException: Cannot format given Object as a Date

Can some one tel me what is mistake? and is htere a better/elegant way of doing this?

Thanks in advance!
9 years ago
Paul, thanks for your reply... finally I figured the way to do it using OutputFormat object.

I kinda overlooked the documentation, thanks for pointing me to it.

Thanks!
I am creating an XML file that will be used on the mainframe machine. But I have some issues with the generated XML file.

I am using the DOM object and XMLWriter class to generate the file. I am using following code




But this generates an XML file that looks like below :

<?xml version="1.0" encoding="UTF-8"?>
<root><doc><info><docDescription> blah blah.... </root>

But I want to remove the encoding="UTF-8" attribute and want the entire XML without any spaces/new line characters like below...
<?xml version="1.0"?><root><doc><info><docDescription> blah blah.... </root>


Does Anyone know how to achieve this???

Thanks in advance.....

Thank you guys for your replies..
10 years ago