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?

Ali Göktaş
  • 15
  • 1
  • 7
  • 1
    May be https://stackoverflow.com/questions/4009756/how-to-count-string-occurrence-in-string can answer your question. – Reporter Jul 13 '18 at 14:16
  • 1
    After you call `split()`, you can use the `length` of the array to see how many elements it has. – Code-Apprentice Jul 13 '18 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 – Igoranze Jul 13 '18 at 14:22
  • @Code-Apprentice this will not work for `//` tho (result will be 0 instead of 2), but you can create `Pattern` then. – GotoFinal Jul 13 '18 at 14:22
  • @Igoranze your right and though, the way to achive it with Java is the same :-) – Reporter Jul 13 '18 at 14:25
  • @reporter similar, as for exact results you need to create `Pattern` object, and it might be hard to notice and see such issue before it happens. – GotoFinal Jul 13 '18 at 14:27
  • What exactly is required, as in the first example you want part of a URL __ID_0000012974.ism__ and in the other example you want other attribute coming after HTTP __baba-candir-4-ekim__ – Aman Chhabra Jul 13 '18 at 14:29
  • @GotoFinal There are serveral ways to count the occurences of a string posted as answers in llinked thread. – Reporter Jul 13 '18 at 14:48
  • You need to step back from the code. Get a pen and paper and write a description **in words** of the steps you need to take to solve this problem. Don't worry much over Java syntax. Just work on getting a good idea of what you need to do. When you have this description, you can work on writing Java code to implement it. – Code-Apprentice Jul 13 '18 at 15:25

0 Answers0