aspose file tools*
The moose likes Beginning Java and the fly likes split string and number Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "split string and number" Watch "split string and number" New topic
Author

split string and number

mark smith
Ranch Hand

Joined: Apr 05, 2005
Posts: 250
hi

i search a way to split a string in two area...
one for string and another for number...

example

aa34
come
aa 34

z342
come

z342

i tried with regex without success

any idea?

thanks
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
mark smith wrote:
i search a way to split a string in two area...
one for string and another for number...

example

aa34
come
aa 34

z342
come

z342

i tried with regex without success

What did you try?

I see that in your first example, the result has a space between the letters and the number, but in your second example, the result does not.

For a regular expression to work, the first thing to do is to define clearly what is regular about it. Is your String always in the format of n-letters and m-numbers without spaces, gaps or white space? If you can define the pre-parse and post-parse formats clearly, we can help you towards a workable solution.
mark smith
Ranch Hand

Joined: Apr 05, 2005
Posts: 250
my error...

aa34
come
aa 34

zt42
come
zt 42

i don't know the number of letter and the number of digit...

the only thing i know it's that begin by a letter and end by a nubmer

i tried to find the first number and to split before this position... a regex seem a better solution
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
mark smith wrote:
i don't know the number of letter and the number of digit...
the only thing i know it's that begin by a letter and end by a nubmer
i tried to find the first number and to split before this position... a regex seem a better solution


I'm no regex expert, but perhaps using look-ahead and look-behind for a non-digit word character next to a digit character is what you need. For e.g.,


i.e.,
Deepak Prakash
Greenhorn

Joined: Apr 11, 2010
Posts: 13
pete stein wrote:
mark smith wrote:
i don't know the number of letter and the number of digit...
the only thing i know it's that begin by a letter and end by a nubmer
i tried to find the first number and to split before this position... a regex seem a better solution


I'm no regex expert, but perhaps using look-ahead and look-behind for a non-digit word character next to a digit character is what you need. For e.g.,


i.e.,


Cool..
Dovev Hefetz
Greenhorn

Joined: Jan 19, 2012
Posts: 1
The Apache Commons libarary has splitByCharacterType(), for anyone searching the forums.

http://commons.apache.org/lang/api-2.5/org/apache/commons/lang/StringUtils.html#splitByCharacterType%28java.lang.String%29

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38818
    
  23
Welcome to the Ranch Dovev Hefetz. That looks a useful method.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: split string and number