0

I'm trying to capitalize the first character of each word in a string in Java. Yes I've done my research, I found this How to capitalize the first character of each word in a string. I've downloaded the binaries but I have no clue how to install them. So how do I install Lang https://commons.apache.org/proper/commons-lang/. Thank you, SQL :P

EDIT: I'm using Eclipse. I wish to use the method capitalizeFully() that is in WordUtils. How would I do this?

Community
  • 1
  • 1
cubecubed
  • 228
  • 4
  • 18

3 Answers3

2

Download latest version of Apache Commons Lang commons-lang3-version-bin.zip

Currenly commons-lang3-3.1-bin.zip

Place the jar file commons-lang3-version.jar in your class path and

import org.apache.commons.lang.WordUtils;

in your class

Finally use

WordUtils.capitalize(str) or WordUtils.capitalizeFully(str)

Sandhu Santhakumar
  • 1,678
  • 1
  • 13
  • 24
  • Thank you for your answer it worked and also made me realize that when ever someone answers me in a forum or something I always forget to do the big part directly in the middle of the post. – cubecubed Nov 15 '13 at 03:58
0

write the code yourself. Look at the java docs for the string class. mystring.charAt(index).toUpperCase

Jesse Nelson
  • 776
  • 8
  • 21
  • OP will need to split original string into words first. Then apply your code assigning the result to a new string. Then concatenate words back into a string. – PM 77-1 Nov 15 '13 at 03:42
  • True, I was just trying to give him a head start into looking at the documentation. – Jesse Nelson Nov 15 '13 at 04:11
0

When you got the Space in string using charAt(index) , You can make index+1 char in Capital by charAt(index).toCapital