• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MetaCharacter Problem(See if you can Solve it)

 
Harshit Sethi
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator






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
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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]
 
Harshit Sethi
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no.please Explain a little bit more
 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please QuoteYourSources
and UseCodeTags
that will really make people easier for helping you
 
Harshit Sethi
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah ,problem is solved ,thanks.But why does space makes such a difference in square brackets?
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The regex engine in java is sensitive to it. Take a look at this code



The output should help explain your problem
 
Harshit Sethi
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It means we can use either "\s" or manually insert space in square brackets.Thats the same thing .Isn't it?
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Regex \s is a short for [\t\n\x0b\r\f]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic