aspose file tools*
The moose likes Beginning Java and the fly likes Have Simple Code Snippet, Please Point Out My Error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Have Simple Code Snippet, Please Point Out My Error" Watch "Have Simple Code Snippet, Please Point Out My Error" New topic
Author

Have Simple Code Snippet, Please Point Out My Error

Bd Howard
Greenhorn
Ranch Hand

Joined: Mar 30, 2012
Posts: 80
Hi,

As seen below, I am trying to figure out how split my sample string so that the "012" is not placed into the string array. After reading the Javadocs, I know that ^0-9 and \D are equivalent, and my output confirms this, but I thought those would return anything NOT a digit. So I tried the regex [a-z][A-Z] on splitChar which I thought would return only letters, but as you see below, that succeeded in returning the whole sample string, digits and all.

This leads me to believe either I have a fundamental misunderstanding of how this whole regex thing works, or I am missing something easy in my code.




And here are my results from the above code:


Length is: 5
012
This
is
the
string

Length is: 1
012

Length is: 1
012

Length is: 1
012 This is the string




Thank you for your help. :-)

BD


I've got just enough Java knowledge to royally screw everything up. :-)
Bd Howard
Greenhorn
Ranch Hand

Joined: Mar 30, 2012
Posts: 80
I was able to get the result I was looking for using:

String[] splitNum = name.split("[0-9]{3}\\s");

I was hoping for a way to just take a shortcut in stripping out those digits, but it now appears to me that it will be a multi-step process to do what I want to do. The above code was just to learn what was going on.

Oh well. :-)

BD
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Have Simple Code Snippet, Please Point Out My Error