我想寫一個將CamelCase轉換爲人類可讀名稱的方法。 這與this question非常相似,但現在帶有下劃線。如何將下劃線轉換爲Java中的人類可讀名稱?
這裏的測試用例:
public void testSplitUnderscore() {
assertEquals("lowercase", splitUnderscore("lowercase"));
assertEquals("Class", splitUnderscore("Class"));
assertEquals("My Class", splitUnderscore("My_Class"));
assertEquals("HTML", splitUnderscore("HTML"));
assertEquals("PDF Loader", splitUnderscore("PDF_Loader"));
assertEquals("A String", splitUnderscore("A_String"));
assertEquals("Simple XML Parser", splitUnderscore("Simple_XML_Parser"));
assertEquals("GL 11 Version", splitUnderscore("GL_11_Version"));
assertEquals("99 Bottles", splitUnderscore("99_Bottle"));
assertEquals("May 5", splitUnderscore("May_5"));
assertEquals("BFG 9000", splitUnderscore("BFG_9000"));
assertEquals("beginning", splitUnderscore("_beginning"));
assertEquals("end", splitUnderscore("end_"));
assertEquals("double middle", splitUnderscore("double__middle"));
assertEquals("double end", splitUnderscore("double_end__"));
assertEquals("double start", splitUnderscore("__double_start"));
assertEquals("double start middle end", splitUnderscore("__double_start__middle_end__"));
}
退房[阿帕奇百科全書(http://commons.apache.org /)...幹。 –
爲什麼所有的票都是反對票?我該如何改進這個問題? – Whitecat
@EddieB什麼是DRY?我沒有找到任何名爲DRY的項目。 – Whitecat