Hello I want to remove the last word from my sentence in C#. Here is my query:
\"SELECT * FROM People WHERE City = @City AND County = @County AND\"
>
If the final word is always going to be "AND":
if (yourString.EndsWith(" AND"))
yourString = yourString.Remove(yourString.Length - 4);
Or, if you need to truncate everything beyond the final space:
int index = yourString.LastIndexOf(' ');
if (index > -1)
yourString = yourString.Remove(index);
(Although, as Donnie says, the real correct answer is to not append the superfluous final word to your string in the first place.)