From: www on
www wrote:
> Hi,
>
> I have a String "dirA/dirB/dirC/file.txt". How to use String
> manipulation technique to get "file.txt"?
>
> String fullName = "dirA/dirB/dirC/file.txt";
>
> int index = fullName.lastIndexOf("\\"); //here is a problem, if I try
> lastIndexOf("\"), there is a compile error
>
> String fileName = fullName.subString(index); //but does not work
>
> Thank you very much.
>
> ps: I am working on linux.

Sorry. I got it work. It was a typo:

int index = fullName.lastIndexOf("\\"); //typo

int index = fullName.lastIndexOf("/"); //now it is correct
From: Daniel Pitts on
On 3/4/2010 12:31 PM, Mike Schilling wrote:
> www wrote:
>> www wrote:
>>> Hi,
>>>
>>> I have a String "dirA/dirB/dirC/file.txt". How to use String
>>> manipulation technique to get "file.txt"?
>>>
>>> String fullName = "dirA/dirB/dirC/file.txt";
>>>
>>> int index = fullName.lastIndexOf("\\"); //here is a problem, if I
>>> try lastIndexOf("\"), there is a compile error
>>>
>>> String fileName = fullName.subString(index); //but does not work
>>>
>>> Thank you very much.
>>>
>>> ps: I am working on linux.
>>
>> Sorry. I got it work. It was a typo:
>>
>> int index = fullName.lastIndexOf("\\"); //typo
>>
>> int index = fullName.lastIndexOf("/"); //now it is correct
>
> Better, becasue it will handle more general file name syntax (e.g. both /
> and \ on Wondows):
>
> File f = new File(str);
> String name = f.getName();
I wonder if it works on VMS, where the native structure is strange :-)


--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
From: Arne Vajhøj on
On 04-03-2010 17:22, Daniel Pitts wrote:
> On 3/4/2010 12:31 PM, Mike Schilling wrote:
>> www wrote:
>>> www wrote:
>>>> I have a String "dirA/dirB/dirC/file.txt". How to use String
>>>> manipulation technique to get "file.txt"?
>>>>
>>>> String fullName = "dirA/dirB/dirC/file.txt";
>>>>
>>>> int index = fullName.lastIndexOf("\\"); //here is a problem, if I
>>>> try lastIndexOf("\"), there is a compile error
>>>>
>>>> String fileName = fullName.subString(index); //but does not work
>>>>
>>>> Thank you very much.
>>>>
>>>> ps: I am working on linux.
>>>
>>> Sorry. I got it work. It was a typo:
>>>
>>> int index = fullName.lastIndexOf("\\"); //typo
>>>
>>> int index = fullName.lastIndexOf("/"); //now it is correct
>>
>> Better, becasue it will handle more general file name syntax (e.g. both /
>> and \ on Wondows):
>>
>> File f = new File(str);
>> String name = f.getName();
> I wonder if it works on VMS, where the native structure is strange :-)

Java on VMS prefer Unix style paths.

So "dirA/dirB/dirC/file.txt" and not "[.dirA.dirB.dirC]file.txt" ...

Arne