• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help with regex  RSS feed

 
Jordan Smith
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I need some help.
Let's say that i have the following sentence:
It's nice outside,the sun shines!let's go swimming

and I want to capitalize the first letter of a word like this:
It's Nice Outside,The Sun Shines!Let's Go Swimming

How can I do it with

string.replaceall( )?

Thanks!
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't do that with replaceAll().

Try putting the whole sentence into a StringBuilder, iterate through it, then use the isXXX methods of the Character class to work out whether you have a letter or not.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't do that with replaceAll().


You can't do that with replaceAll(), but you can do it with regex. If you would like to try... take a look at the find(), appendReplacement(), and appendTail() methods of the Matcher class.

Henry

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!