This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes MetaCharacter Problem(See if you can Solve it) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "MetaCharacter Problem(See if you can Solve it)" Watch "MetaCharacter Problem(See if you can Solve it)" New topic
Author

MetaCharacter Problem(See if you can Solve it)

Harshit Sethi
Ranch Hand

Joined: Jul 16, 2010
Posts: 75






Run this program with statement:java Parsing "0[xX]([0-9 a-f A-F])+" "0x1FE 320x 0xfF 0xA"

My doubt is that i am not getting 0xA as a hexadecimal number in the output why is that?
Please help.
Prasad Kharkar
Ranch Hand

Joined: Mar 07, 2010
Posts: 438

the command line arguments are all the Strings
did you get the hint?
[EDIT]
and yes
I forgot to tell
UseCodeTags
QuoteYourSources
otherwise it will be difficult for people to help you

so help them help you
happy learning
[/EDIT]


SCJP 6 [86%] June 30th, 2010
OCPWCD [84%] March 26th, 2013
If you find any post useful, click the "plus one" sign on the right
Harshit Sethi
Ranch Hand

Joined: Jul 16, 2010
Posts: 75
no.please Explain a little bit more
Prasad Kharkar
Ranch Hand

Joined: Mar 07, 2010
Posts: 438

please QuoteYourSources
and UseCodeTags
that will really make people easier for helping you
Harshit Sethi
Ranch Hand

Joined: Jul 16, 2010
Posts: 75
ok thanks i have done that now tell me what's the problem .The two Command Line Arguments are already in quotes
Prasad Kharkar
Ranch Hand

Joined: Mar 07, 2010
Posts: 438

hahaha
QuoteYourSources means mention the book or web site from where you got this question
let it be


first of all let me apologize that I mislead you about the question
the problem is not with command line arguments

it is with the String you are passing
the pattern should be

0[xX][0-9a-fA-F]

and not the

0[xX][0-9 a-f A-F]

the spaces should not be there
it causes the different output

Harshit Sethi
Ranch Hand

Joined: Jul 16, 2010
Posts: 75
I firstly didn't include any spaces between them but then because i didn't get the last hexadecimal number then i did that way but the result was same .

This problem is from Kathy Sierra but the second command line argument i have taken as random choice of mine.

Prasad Kharkar
Ranch Hand

Joined: Mar 07, 2010
Posts: 438

does that mean that problem is not solved?
because I had the output as expected

this is it

C:\Users\Prasad\Desktop>java Parsing "0[xX]([0-9 a-f A-F])+" "0x1FE 320x 0xfF 0x
A"
0 9 0x1FE 320
11 17 0xfF 0

C:\Users\Prasad\Desktop>java Parsing "0[xX]([0-9a-fA-F])+" "0x1FE 320x 0xfF 0xA"

0 5 0x1FE
11 15 0xfF
16 19 0xA
Harshit Sethi
Ranch Hand

Joined: Jul 16, 2010
Posts: 75
Yeah ,problem is solved ,thanks.But why does space makes such a difference in square brackets?
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

The regex engine in java is sensitive to it. Take a look at this code



The output should help explain your problem


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Harshit Sethi
Ranch Hand

Joined: Jul 16, 2010
Posts: 75
It means we can use either "\s" or manually insert space in square brackets.Thats the same thing .Isn't it?
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

Regex \s is a short for [\t\n\x0b\r\f]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MetaCharacter Problem(See if you can Solve it)
 
Similar Threads
Multi-dimensional array
conversion Doubt
What this code does
Numeric Literals that include a comma
[Easy]hyphen