There are difeferent way that you can do such operation .
Here first remove the spaces by using
Trim()
operator and then split the string by spaces.
string[] arr=x.Trim().Split(null);
now remove the last word by using LINQ operation
arr = arr.Where((o, i) => i != arr.Length - 1).ToArray();
Last you make a
Join
operator to join the array items and make a string
x = string.Join(" ", arr);
Hope it helps you
thanks