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
  • 44,617
  • 6
  • 35
  • 64
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,485
  • 5
  • 50
  • 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
  • 3,035
  • 23
  • 25