how can I use a different function \"InStr\" this is the code that I am using and works fine but moving away from InStr is my goal
i = InStr(1, Hostname, Env
If you need equivalent C# code you can use Strings class from Microsoft.VisualBasic assembly, thus code can be like following:
using Microsoft.VisualBasic;
. . .
i = Strings.InStr(1, Hostname, Environment.NewLine);

Another approach is using appropriate String.Indexof function.
Links: