informatiklehrling
Goto Top

Android - Leerzeichen nach jedem Character eines Strings

Hallo Administartoren

Ich versuche gerade ein kleines Android-Programm zu schreiben, dabei muss ich in einem String zwischen jeden Character drei Leerzeichen einfügen lassen. Ich habs mit "String.format("%3s", String)" probiert, jedoch funktioniert es leider nicht..
Bisher sieht der Codeteil so aus:

String result = String.format("%3s", firstcolumn); //Hier sollten die 3 Leerzeichen hinter jeden Character
for (int i = 0; i < firstcolumn.length(); i++) {
String line = String.format("\n") + firstrow.substring(i, i + 1);
for (int j = 0; j < firstrow.length()-1; j++) {
line += String.format("%3d", levenshtein[i][j]);
}
result += line;
}

Danke schonmal im vorraus.

Gruss

Informatiklehrling

Content-Key: 206126

Url: https://administrator.de/contentid/206126

Printed on: April 25, 2024 at 04:04 o'clock

Member: colinardo
colinardo May 07, 2013 at 08:38:41 (UTC)
Goto Top
Hallo Stift face-wink
probier mal das:
String result = "";  
for (int i=0; i<firstcolumn.length() ; i++) {
     char c = column.charAt(i);
     finalString += c + "   ";  
}
System.out.println(result);

Grüße Uwe
Member: informatiklehrling
informatiklehrling May 07, 2013 at 08:44:27 (UTC)
Goto Top
Hey Colinardo

Danke für deine Antwort/Lösung.
Funktioniert genau so wie ich es wollte :D

Wünsch dir noch einen schönen Tag

Gruss Stift ;)
Member: colinardo
colinardo May 07, 2013 updated at 09:01:23 (UTC)
Goto Top
Keine Ursache.

Hier noch ein Schnippsel für das n-mal wiederholen von bestimmten Strings:
int n = 3;
String zeichen = " ";  
String dreimalLeerzeichen = String.format("%0" + n + "d", 0).replace("0",zeichen);  
Member: informatiklehrling
informatiklehrling May 07, 2013 at 14:35:02 (UTC)
Goto Top
Ok und nochmal danke ;D