Question: I have string like this:

```
com.company.foobar.message 

```

And the other input to function is another string "foobar".

Now, I need to format the string in such a way that I will return foobar.message as the resulting string. The position of foobar in the original string is not fixed.

Answer: 
Just find the location of foobar, and take the rest of the string.

```
int index = str.indexOf("foobar");
if (index != -1) {
   return str.substring(index);
} else {
   // not found - do something
}

```
You can do it in this way assuming that you need everything after that foobar

```
package com;

public class Test {

    public static void main(String[] args) {
        String string = "com.company.foobar.message";
        String returnValue=Checkfor(string,"foobar");
        System.out.println(returnValue);

    }

    private static String Checkfor(String string, String string2) {
        int start=string.indexOf(string2);
        if (start!=-1){
            return string.substring(start);
        }
        else
        // TODO Auto-generated method stub
        return null;
    }
} 

```

OUTPUT
`foobar.message`