Results 1 to 8 of 8
Thread: Dude in replace
- 03-24-2012, 05:34 PM #1
Member
- Join Date
- Oct 2011
- Posts
- 18
- Rep Power
- 0
Dude in replace
I explain problem.
My program needs to know all numbers, possitive an negative
I know how to replace all the chars that aren't digits, but i dont know how to do for - that say a number is < 0 dont remove
Eg:
String s = " hello, -3World, My name Pedro234"
then i use
s.replaceAll("\\D" , " ");
and the result is :
3 234
but not
-3 234
this is because \\D remove all that arent a digit, i dont know a form to do it without removing - ç
thx to all
-
Re: Dude in replace
Moved from advanced java forum
- 03-24-2012, 06:09 PM #3
Senior Member
- Join Date
- Aug 2008
- Location
- Stockholm, Sweden
- Posts
- 119
- Rep Power
- 0
Re: Dude in replace
Google: replaceAll() digits
- 03-24-2012, 06:18 PM #4
Member
- Join Date
- Oct 2011
- Posts
- 18
- Rep Power
- 0
Re: Dude in replace
but it thas what i explai raplace all negative numbers too
- 03-25-2012, 09:23 AM #5
Re: Dude in replace
You could use String.split() with a regex that matches both positive and negative numbers. Something like "-?[1-9][0-9]*", although I don't remember off the top of my head if the '-' would need to be escaped there.
Get in the habit of using standard Java naming conventions!
-
Re: Dude in replace
- 03-25-2012, 04:42 PM #7
Senior Member
- Join Date
- Aug 2008
- Location
- Stockholm, Sweden
- Posts
- 119
- Rep Power
- 0
- 03-25-2012, 06:10 PM #8
Re: Dude in replace
And actually, my reasoning was backward... using split with a regex like the one I suggested would give you everything except the numbers you're interested in. You'd want to use that regex with a Matcher.
Get in the habit of using standard Java naming conventions!
Similar Threads
-
Char replace
By susieferrari in forum New To JavaReplies: 4Last Post: 06-08-2011, 02:06 PM -
Find and replace
By ravikanth.29 in forum AWT / SwingReplies: 1Last Post: 03-14-2011, 09:46 AM -
Replace String
By Raeghin in forum New To JavaReplies: 1Last Post: 07-28-2009, 03:58 PM -
Hello from an old dude
By fishtoprecords in forum IntroductionsReplies: 4Last Post: 06-29-2008, 05:38 AM -
Hello from an even older Dude
By Alan-LB in forum IntroductionsReplies: 10Last Post: 06-29-2008, 05:29 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks