Tuesday, 15 April 2014

How to get a part of a string in java? -



How to get a part of a string in java? -

basically, have these strings:

/path/to/pbox01/file1_#$%encryp /path/to/pbox01/file4_#$%encryp /path/to/pbox02/file2_#$%encryp

and want file1, file4, file2 each iteration. filenames, , can anything(like file, stack, blahblahblah. first want part after lastly slash - part i'm having biggest problems with. ending hardset, want trim _#$%encryp, 10 characters - i'll use:

public string removelastchar(string s) { if (s == null || s.length() == 0) { homecoming s; } homecoming s.substring(0, s.length()-10); }

so, summarize, question is: how can part of string after lastly /?

i think might utilize string.lastindexof(int) like,

public string removelastchar(string s) { if (s == null || s.length() == 0) { homecoming s; } homecoming s.substring(s.lastindexof('/') + 1, s.length() - 10); }

java string

No comments:

Post a Comment