java - Get word part from a variable String -
i've been implementing application retrieve word inside incoming string parameter, string parameter can vary since url, pattern incoming url's same. instance have:
get /com.myapplication.v4.ws.monitoring.modulesystemmonitor http/1.1
or
get /com.myapplication.filesystem.ws.modulefilesystem/getidfolders/jsonp?idfolder=idfis1&callback=__gwt_jsonp__.p0.onsuccess&failurecallback=__gwt_jsonp__.p0.onfailure http/1.1
so in case, want extract word starts module, example, first incoming parameter want get: modulesystemmonitor. , second 1 want word: modulefilesystem.
this requirement, i'm not allowed else this: method receives line , try extract words mentioned: modulesystemmonitor , modulefilesystem.
i've been thinkng of using stringtokenizer
class or string#split
method, i'm not sure if best option. tried , easy word begins module using indexof, how cut word if cases comes white space first sample or comes "/" (slash) in second. know can make "if" statement , cut when white space or slash wonder know if there way more dynamic.
thanks in advance time , help. best regards.
i'm not sure best solution try this:
string[] tmp = yourstring.split("\\.|/| "); (int i=0; i< tmp.length(); i++) { if (tmp[i].matches("^module.*")) { return tmp[i]; } } return null;
Comments
Post a Comment