Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

Put tabs into Strings

Thread view: 
feju2000@gmx.de - 17 Jan 2006 23:00 GMT
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
IchBin - 18 Jan 2006 04:37 GMT
> Hallo,
> ich habe ein Problem, was mich wirklich verrückt macht.
[quoted text clipped - 20 lines]
> 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-)
hiwa - 18 Jan 2006 06:21 GMT
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.
feju2000@gmx.de - 18 Jan 2006 10:51 GMT
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
Roedy Green - 18 Jan 2006 11:57 GMT
>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.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

feju2000@gmx.de - 18 Jan 2006 13:29 GMT
No, I am writing "xxx\txxxx" and in the file it's also "xxx\txxxx"!
Roedy Green - 18 Jan 2006 13:47 GMT
>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.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

feju2000@gmx.de - 18 Jan 2006 14:22 GMT
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
Roedy Green - 18 Jan 2006 15:40 GMT
>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.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

feju2000@gmx.de - 18 Jan 2006 22:37 GMT
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???
Roedy Green - 18 Jan 2006 15:38 GMT
On Wed, 18 Jan 2006 13:47:37 GMT, Roedy Green
<my_email_is_posted_on_my_website@munged.invalid> wrote, quoted or
indirectly quoted someone who said :

>>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.

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.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.