is it possible to use a backslash as a StringTokenizer delimiter?  
Author Message
greenzy





PostPosted: 2004-2-22 5:47:00 Top

java-programmer, is it possible to use a backslash as a StringTokenizer delimiter? I am trying to tokenize a file path to compare it to another.

i.e tokenize: ways\gov\marketing.fls

to compare each directory seperately.

Is it possible to use the "\" (backslash) character as a StringTokenizer
delimiter, and if so how?

if not, any ideas on how to seperate this string?

Any help greatly appreciated

Thanks
Greenz


 
JosMar韆 Mateos





PostPosted: 2004-2-22 7:24:00 Top

java-programmer >> is it possible to use a backslash as a StringTokenizer delimiter? -----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

In comp.lang.java.help, greenzy (email***@***.com) wrote:
> Is it possible to use the "\" (backslash) character as a StringTokenizer
> delimiter, and if so how?

Have you tried "\\"? Backslash is special character and needs to
be scaped.

Regards.

- --
My real e-mail address: chema (AT) chema.homelinux.org
http://EuropeSwPatentFree.hispalinux.es - EuropeSwPatentFree
I don't read HTML posts / No leo mensajes en HTML
Blog Overflow: http://chema.homelinux.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFAN+iT9P6GbSlI+hkRAt21AKCjPHARQdh0T/kFLcSEKd/xkQqKewCfQCEi
yjkXdNrKAMSjLFWKjq+I8CQ=
=Zp0l
-----END PGP SIGNATURE-----
 
GoGoGoGo





PostPosted: 2004-2-23 6:13:00 Top

java-programmer >> is it possible to use a backslash as a StringTokenizer delimiter? I believe it was '\' or "\" or '\\' or "\\".

Something like that........

good luck


"greenzy" <email***@***.com> wrote in message
news:RlQZb.583331$X%5.213137@pd7tw2no...
> I am trying to tokenize a file path to compare it to
another.
>
> i.e tokenize: ways\gov\marketing.fls
>
> to compare each directory seperately.
>
> Is it possible to use the "\" (backslash) character as a
StringTokenizer
> delimiter, and if so how?
>
> if not, any ideas on how to seperate this string?
>
> Any help greatly appreciated
>
> Thanks
> Greenz
>
>


 
 
joeking





PostPosted: 2004-2-24 19:36:00 Top

java-programmer >> is it possible to use a backslash as a StringTokenizer delimiter? "greenzy" <email***@***.com> wrote in message news:<RlQZb.583331$X%5.213137@pd7tw2no>...
> I am trying to tokenize a file path to compare it to another.
>
> i.e tokenize: ways\gov\marketing.fls
>
> to compare each directory seperately.
>
> Is it possible to use the "\" (backslash) character as a StringTokenizer
> delimiter, and if so how?


As noted elsewhere, you need to escape the backslash with another
backslash, thus: '\\'.

Have you considered looking around the java.io package to see if the
functionality you require is already in existance? Classes like File
etc. have the ability to interpret and compare filenames in a platform
neutral manner, IIRC...

-FISH- ><>
 
 
Alex Hunsley





PostPosted: 2004-2-24 19:53:00 Top

java-programmer >> is it possible to use a backslash as a StringTokenizer delimiter? greenzy wrote:
> I am trying to tokenize a file path to compare it to another.
>
> i.e tokenize: ways\gov\marketing.fls
>
> to compare each directory seperately.
>
> Is it possible to use the "\" (backslash) character as a StringTokenizer
> delimiter, and if so how?
>
> if not, any ideas on how to seperate this string?
>
> Any help greatly appreciated
>
> Thanks
> Greenz

I think the others have maybe answered your question.
I want to add something, however...
If you're tokenizing a file path, *don't* just hardcode "\" into your
aplpication - it's not very portable, because if you run your java app
on another system like linux etc. it may no longer work.
Instead, use File.pathSeparator - this is a string that contains the
seperator for the current system.
(If you want it as a char, File.pathSeparatorChar is available.)

(See the File class for more details.)

HTH,
alex

 
 
Stewart Gordon





PostPosted: 2004-2-24 22:49:00 Top

java-programmer >> is it possible to use a backslash as a StringTokenizer delimiter? While it was 2/24/04 11:52 AM throughout the UK, Alex Hunsley sprinkled
little black dots on a white screen, and they fell thus:

<snip>
> I think the others have maybe answered your question.
> I want to add something, however...
> If you're tokenizing a file path, *don't* just hardcode "\" into your
> aplpication - it's not very portable, because if you run your java app
> on another system like linux etc. it may no longer work.
> Instead, use File.pathSeparator - this is a string that contains the
> seperator for the current system.
<snip>

You mean we've yet another place where Java isn't platform-independent?

Surely "/" should work as an alternative to "\\"? IRS that even the C
library supports this.

Stewart.

--
My e-mail is valid but not my primary mailbox, aside from its being the
unfortunate victim of intensive mail-bombing at the moment. Please keep
replies on the 'group where everyone may benefit.
 
 
Andrew Thompson





PostPosted: 2004-2-24 23:11:00 Top

java-programmer >> is it possible to use a backslash as a StringTokenizer delimiter? Stewart Gordon wrote:
> While it was 2/24/04 11:52 AM throughout the UK, Alex Hunsley
> sprinkled little black dots on a white screen, and they fell thus:
>
> <snip>
>> I think the others have maybe answered your question.
>> I want to add something, however...
>> If you're tokenizing a file path, *don't* just hardcode "\" into your
>> aplpication - it's not very portable, because if you run your java
>> app on another system like linux etc. it may no longer work.
>> Instead, use File.pathSeparator - this is a string that contains the
>> seperator for the current system.
> <snip>
>
> You mean we've yet another...

..troll who cannot read the API?

>..place where Java isn't
> platform-independent?

Oh, ...no.

You want platform independence?

Use an URI, if OTOH, you want to access
the same resources using the filesystem of the
underlying OS, use whatever it speaks..


 
 
Jon A. Cruz





PostPosted: 2004-2-25 1:01:00 Top

java-programmer >> is it possible to use a backslash as a StringTokenizer delimiter? Stewart Gordon wrote:
>
> You mean we've yet another place where Java isn't platform-independent?
>
> Surely "/" should work as an alternative to "\\"? IRS that even the C
> library supports this.

Well...

Java has things more portable by using java.io.File.