Solved

Fetching package name from string input  - java

Posted on 2013-06-10
7
758 Views
Last Modified: 2013-06-10
Hi:

I need to write a function which accepts a url as string. The function should do the following:

If the input is of the first url pattern, it should get the content after the last '/' in the url and before the .apk

If the input is of the second url pattern, it should get the content after the ?id= and before &feature


ie; in short, it should be returning package name from url. How can I accomplish this through java? Any help is appreciated.

PATTERN 1

http://abc.com/data/applications/net.feathertech.mediterraneanrecipes.apk
http://abc.com/data/applications/com.a731412505508e759b5b9717a.a36562546a.apk
http://abc.com/data/applications/com.petwisewebsites.mobile.apk

PATTERN 2

https://play.google.com/store/apps/details?id=com.apofiss.yinthecatlite&feature=personalized-recommendations#?t=W251bGwsMSwxLDIxMywiY29tLmFwb2Zpc3MueWludGhlY2F0bGl0ZSJd


https://play.google.com/store/apps/details?id=com.apofiss.pandadumplinglite&feature=more_from_developer#?t=W251bGwsMSwxLDEwMiwiY29tLmFwb2Zpc3MucGFuZGFkdW1wbGluZ2xpdGUiXQ..

https://play.google.com/store/apps/details?id=com.apofiss.chameleon&feature=more_from_developer#?t=W251bGwsMSwxLDEwMiwiY29tLmFwb2Zpc3MuY2hhbWVsZW9uIl0.
0
Comment
Question by:Sreejith22
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 

Author Comment

by:Sreejith22
ID: 39235365
please let me know if any clarification regarding question is required
0
 
LVL 12

Expert Comment

by:Sharon Seth
ID: 39235438
use regex
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 300 total points
ID: 39235457
 s = s.replaceAll(".*/([^&]+).*", "$1").replaceAll(".*=(.*)", "$1");

Open in new window

The above is possibly OK, although it should be possible to do it more elegantly
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:Sreejith22
ID: 39235458
any code snippet is much appreciated. I know regex is the possible way, but , sorry I do not have expertise using it.
0
 

Author Comment

by:Sreejith22
ID: 39235472
Hi cehj,
 it does not exclude apk in first pattern
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39235486
Well you didn't ask for that ;)

Quick and dirty - tack this on at the end

.replaceAll("\\.apk$", "");

Open in new window

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39235611
:)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question