I want to remove the following words from the end of the line 'PTE', 'LTD', 'PRIVATE' and 'LIMITED'
I tried the code but then got stuck. i tried this
String[] str = {"PTE", "LTD", "PRIVATE", "LIMITED"}; String company = "Basit LTD"; for(int i=0;i<str.length;i++) { if (company.endsWith(str[i])) { int position = company.lastIndexOf(str[i]); company = company.substring(0, position); } } System.out.println(company.replaceAll("\\s",""));
It worked. But suppose Basit LIMITED PRIVATE LTD PTE or Basit LIMITED PRIVATE PTE LTD or any four-word combination at the end. Then the above code just removes the last name, i.e. PTE or PRIVATE , etc., and the output is BasitLIMITEDPRIVATELTD .
I want the output to be just Basit
How can i do this?
thanks
--------------- Edit ---
Please note that the name of the company is just an example, it is not necessary that it is always the same. maybe i have a name like
String company = "Masood LIMITED LTD PTE PRIVATE"
or any name that may contain the above words at the end.
thanks
source share