I am developing one application for Windows. In my application, I want to get the last word entered into the text field not the last word. And I want to change the last entered word to the space bar. I get the last word in a key event like this:
private async void mytxt_KeyUp_1(object sender, KeyRoutedEventArgs e) { if (e.Key == Windows.System.VirtualKey.Space || e.Key == Windows.System.VirtualKey.Enter) { if (string.IsNullOrWhiteSpace(textBox_string) == false) { string[] last_words = Regex.Split(textBox_string, @"\s+"); int i = last_words.Count(); last_words = last_words.Where(x => x != last_words[i-1]).ToArray(); last_word = last_words[last_words.Count() - 1]; last_word = last_word.TrimStart(); } } }
I get the last word with this method, but really want to get the last word entered by the user. Value, if the user moves the cursor directly to the middle of the text field and types any word, then I want to get this word in the pressed space bar; I want the position of this word and can change this word programmatically and update the text box. For example, if the user enters
H !! my name is vanani
but then the user moves the cursor immediately after the "name" and the types are ishan
H !! my name is sohan
then I want to get the word and position "is" and also for "sohan" in the key event of the text field. I need a position to replace this word with another word and update the text box with new new text.
I saw these questions. winforms - get the last word .. and C # how to get the last char .. but they didnβt "I will help me. Please help me.
string c # regex textbox windows-phone-8
sohan vanani
source share