Reputation: 43
I can't seem to get StringUtils.capitalize to actually capitalize my whole word string.
I've tried various ways, but I just end up getting sentence-type case. I tried using StringUtils.capitalize inside of what I want to print, but that doesn't work either. Nothing I look up helps me either.
File file =
new File("C:\\Users\\mikek\\Desktop\\name.txt");
BufferedReader abc = new BufferedReader(new FileReader(file));
List<String> data = new ArrayList<String>();
String s;
String t;
while((s=abc.readLine()!=null) {
data.add(s);
System.out.println("public static final Block " + s.toUpperCase() + " = new "
+ StringUtils.capitalize(s).replace("_","") + "(\"" + s + "\", Material.ROCK);");
}
abc.close();
}
Expected: Charcoal Block Got: Charcoal block
Upvotes: 0
Views: 303
Reputation: 43
What Chris Katric helped me figure out:
File file =
new File("C:\\Users\\mikek\\Desktop\\name.txt");
BufferedReader abc = new BufferedReader(new FileReader(file));
List<String> data = new ArrayList<String>();
String s;
while((s=abc.readLine())!=null) {
data.add(s);
String camelCaseSentence = "";
String[] words = s.split("_");
for(String w:words){
camelCaseSentence += w.substring(0,1).toUpperCase() + w.substring(1) + " ";
}
camelCaseSentence = camelCaseSentence.substring(0, camelCaseSentence.length()-1);
System.out.println("public static final Block " + s.toUpperCase() + " = new "
+ camelCaseSentence.replace(" ", "") + "(\"" + s + "\", Material.ROCK);");
}
abc.close();
}
Now I get(for the full part of the System.out.println): "public static final Block CHARCOAL_BLOCK = new CharcoalBlock("charcoal_block", Material.ROCK);" just like I wanted.
Upvotes: 0
Reputation: 51
How about this??
String s = "camel case word";
String camelCaseSentence = "";
String[] words = s.split(" ");
for(String w:words){
camelCaseSentence += w.substring(0,1).toUpperCase() + w.substring(1) + " ";
}
camelCaseSentence = camelCaseSentence.substring(0, camelCaseSentence.length()-1);
System.out.println(camelCaseSentence);
Upvotes: 1