samedi 28 mars 2015

How to switch a tab with multiple spaces without the replace() methods?



I am trying to get my method to swap a tabs from an input file with x amount of spaces and print to a new file, and all it is doing is reprinting the exact same thing into the output file. However, I can't use the replace() methods.


So far I have for the conversion:



public static String expandLine(String line, int numberOfSpaces) {
String tab = "\t";
String formattedLine = "";
String space = spaces(numberOfSpaces);
for (int i = 0; i < line.length(); i++) {
if (line.charAt(i) == tab.charAt(0)) {
formattedLine += space;
} else {
formattedLine += line.charAt(i);
}
}
return formattedLine;
}



Aucun commentaire:

Enregistrer un commentaire