0

I am selecting an item from arraylist

ArrayAdapter.getItem(which)

I am getting the result as Amazon.com%2C%20Inc.-AMZN

I just want the last part that is AMZN of this string to append in my url.

3 Answers3

1

Normal String operation like lastIndexOf and substring

      String str = "Amazon.com%2C%20Inc.-AMZN";

      String result = str.substring(str.lastIndexOf("-") + 1);
      System.out.println(result);

or if there are no other - in the String use

 String endBit = str.split ("-")[1];
Scary Wombat
  • 43,525
  • 5
  • 33
  • 63
1

Please refer this url

How to get a string between two characters?

String s = "Amazon.com%2C%20Inc.-AMZN";

String result = s.substring(s.indexOf("-") + 1);

System.out.println(result);

Output: AMZN

Community
  • 1
  • 1
Dharmbir Singh
  • 17,277
  • 5
  • 49
  • 66
0

try this.

if there is no other -

String val = "Amazon.com%2C%20Inc.-AMZN";
String arr[]=val.split("-");
and at index 1 you can get your value.
like arr[1]// this will contain "AMZN"
Lovekush Vishwakarma
  • 2,661
  • 20
  • 23