Java Split function upon function returning value -


i making function call , using split on return value.

the function call

<c:set var="locale" value="<%= request.getheader("accept-language").split(",")[0] %>"/> 

request.getheader returns this

en,en-us;q=0.8 

i want split in way variable locale has

en-us 

i tried multiple things wasnt able figure out. closest got splitting "0" gives me "en"

you can use regular expressions define more 1 character delimiter:

    string test = "en,en-us;q=0.8";     string[] tokens = test.split("[,;]");     system.out.println(tokens[1]); 

prints

en-us

the brackets can interpreted "one of". string split 1 of characters , or ;.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -