0

I'm reading a log file line by line and I use "white spaces,\"(quotation),/(slash)" to split them.However,there are some lines which have more slash than others.EX:

173.172.12.134 - - [05/Oct/2015:06:37:26 +0300] "GET /h/8K/ID_0000012974.ism/QualityLevels(96000)/Fragments(audio=45302184354) HTTP/1.1" 200 25285 "-" "Firefox/1.5" "-" rt=0.000 ut="-" cs=HIT 

When I do this strLine.split(" |\"")[7].split("/")[3]---> this is what I want that content name>ID_0000012974.ism

But in this line:

98.207.17.70 - - [05/Oct/2015:06:47:40 +0300] "GET /clientaccesspolicy.xml HTTP/1.1" 304 0 "baba-candir-4-ekim" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/601.1.56 (KHTML, like Gecko) Version/9.0 Safari/601.1.56" "-" rt=0.000 ut="-" cs=HIT 

I need this-->baba-candir-4-ekim as a content name.

I tried that if(strLine.split(" |\"")[7].split("/")[3].contains(" /|/|/"))

but it does not work.How can I check how many "/" does it have?

9
  • 1
    May be stackoverflow.com/questions/4009756/… can answer your question. Commented Jul 13, 2018 at 14:16
  • 1
    After you call split(), you can use the length of the array to see how many elements it has. Commented Jul 13, 2018 at 14:16
  • @reporter Although JS is similar to Java, it's not the same, functions may vary. If you want to link another SO Q&A, please be sure it contains the same language Commented Jul 13, 2018 at 14:22
  • @Code-Apprentice this will not work for // tho (result will be 0 instead of 2), but you can create Pattern then. Commented Jul 13, 2018 at 14:22
  • @Igoranze your right and though, the way to achive it with Java is the same :-) Commented Jul 13, 2018 at 14:25

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.