Java Utililty Methods File Name Create

List of utility methods to do File Name Create

Description

The list of methods to do File Name Create are organized into topic(s).

Method

StringtoFilename(String key, final String suffix)
to Filename
String filename = key.substring(key.lastIndexOf("/") + 1); 
filename = filename.substring(0, filename.length() - suffix.length()); 
return filename;
StringtoFileName(String moduleName)
Returns the file name implementing the module.
return moduleName + ".js";
StringtoFilename(String name, String extension)
to Filename
return toFilename(name, "", extension); 
StringtoFilename(String s)
Invokes toLowerCase(), converts all whitespaces to underscores and removes all characters other than a-z, 0-9, dot, underscore or minus.
s = s.toLowerCase();
s = s.replaceAll("\\s+", "_");
s = s.replaceAll("[^a-z_0-9.-]", "");
return s;
StringtoFileName(String s)
Replaces all the special characters in s string with an underscore
return s.replaceAll("[^A-Za-z0-9_]", "_");
StringtoFileName(String str)
Change "Text Extractor Worker" or "Text extractor worker" to "TextExtractorWorker".
StringBuilder sb = new StringBuilder();
boolean toUpper = true;
for (int i = 0; i < str.length(); i++) {
    char c = str.charAt(i);
    if (c == ' ') {
        toUpper = true;
        continue;
    } else if (toUpper) {
...
StringtoFilename(String str)
to Filename
return str.replaceAll("\\s", "_").replaceAll(":", "_");