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
Post a Comment