Put tabs into Strings

F

feju2000

Hallo,
ich habe ein Problem, was mich wirklich verrückt macht.
Als erstes lese ich Strings aus einer tab-separierten Datei.
Ein Parameter namens cutchar gibt an, welcher String separiert.
Da es sich bei "\t" um einen regulären Ausdruck handelt, muss ich zum
Parsen die Klasse Pattern benutzen.
Das funktioniert auch noch alles!
Wenn ich allerdings versuche, den Parameter cutchar (auch gern mithilfe
der Klasse Pattern) zu einem String (um diesen zu separieren)
hinzuzufügen, geht es einfach nicht.
Ich habe schon einiges ausprobiert, es geht aber einfach nicht!

StringBuffer out = new StringBuffer("");
String delim = Pattern.compile(delimiter).toString();
out.append((String)(s.x(i)));
out.append(delim);
out.append(tagString);
bw.write(out + "\n");

geht also nicht!!!
Habt ihr irgendwelche Vorschläge?

Danke,
Felix
 
I

IchBin

Hallo,
ich habe ein Problem, was mich wirklich verrückt macht.
Als erstes lese ich Strings aus einer tab-separierten Datei.
Ein Parameter namens cutchar gibt an, welcher String separiert.
Da es sich bei "\t" um einen regulären Ausdruck handelt, muss ich zum
Parsen die Klasse Pattern benutzen.
Das funktioniert auch noch alles!
Wenn ich allerdings versuche, den Parameter cutchar (auch gern mithilfe
der Klasse Pattern) zu einem String (um diesen zu separieren)
hinzuzufügen, geht es einfach nicht.
Ich habe schon einiges ausprobiert, es geht aber einfach nicht!

StringBuffer out = new StringBuffer("");
String delim = Pattern.compile(delimiter).toString();
out.append((String)(s.x(i)));
out.append(delim);
out.append(tagString);
bw.write(out + "\n");

geht also nicht!!!
Habt ihr irgendwelche Vorschläge?

Danke,
Felix
Mein Vorschlag würde auf englisch, meine Bablel Fische schreiben sollen,
in meinem Ohr, versteht nicht Ihren deutschen Dialekt. Ich benötige mehr
Code als, was Sie für diese Frage gegeben haben.


Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
 
H

hiwa

Ich verstehe nicht Ihre Beschreibung des Problems.
Und, der Code, der angebracht wird, ist wegen der
unbekannten Symbole wie ' delim ', ' s, ' x ' usw. unverständlich.
Außerdem statement:
String delim = Pattern.compile(delimiter).toString();
ist ungewöhnlich und sonderbar.
 
F

feju2000

Okay, next try in English:
I just want to separate some Strings with a tab.
The tab is in the String delim and looks like "\t"!
The Problem is, that if I write the String down in a file, the lines
are not Tab-separated but written together just with a \t between them!

Felix
 
R

Roedy Green

are not Tab-separated but written together just with a \t between them!
are you writiing "xxx\\txxxx" in your program? It should be just
"xxx\txxx"

It depends on your viewer how that tab is displayed. Use a hex viewer
to make sure the file is correct.
 
R

Roedy Green

No, I am writing "xxx\txxxx" and in the file it's also "xxx\txxxx"!

What was it in hex? 09, that is correct. 5C 74? then your \t literal
is not being interpreted. \t only works in a literal in quotes in
source code. It wont work if you wrote (char)0x5c + ( char )0x74 to
the output file.
 
F

feju2000

Okay, but I get the separating (in this case \t) String from a gui as
input.
How shall I parse (or format) the input to get a real tab in the
resulting file?

Thanks
 
R

Roedy Green

What was it in hex? 09, that is correct. 5C 74? then your \t literal
is not being interpreted. \t only works in a literal in quotes in
source code. It wont work if you wrote (char)0x5c + ( char )0x74 to
the output file.

maybe you want it expanded to spaces? I wrote an old dos utility to
do that still works under windows. See
http://mindprod.com/jgloss/tabout.html
I have also written a java one. It is the old C one that is posted
though.
 
R

Roedy Green

Okay, but I get the separating (in this case \t) String from a gui as
input.
How shall I parse (or format) the input to get a real tab in the
resulting file?

Please talk in hex. Otherwise every thing you say is ambiguous.

String.replace ( "\\t", "\t") is what you want.
 
F

feju2000

Hi,
the problem is, that it is 5C 74 in hex!
But I cannot just use String.replace ( "\\t", "\t"), because the
separating String maybe also for example \s or whatever.
The question now is, how to parse a "\t" which is 5C 74 in hex to a
"\t" which is a 09 in hex???
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,416
Messages
2,571,562
Members
48,797
Latest member
shadowoftheunknown

Latest Threads

Top