Hello, I want simple and easy solution to extract or get string between two strings in C#, so for example I have string "Hello World, I am .NET developer", I need output as "I am" only.
How can i do it in simple and fast way? Thanks
Since, we need string between "," and "." so we already know from where to extract string, we can use .substring()
string str = "Hello World, I am .NET developer"; int startPoint = str.IndexOf(",") + ",".Length; int endPOint = str.LastIndexOf("."); String result = str.Substring(startPoint, endPOint - startPoint); Console.WriteLine(result);
and this will give output
string str = "Hello World, I am .NET developer"; var match = Regex.Match(str, @"(\s([a-zA-Z]+\s)+)").Groups.Value; Console.WriteLine(match);
Hope it helps, Thanks
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly