I am developing one Windows phone app. In my app I want to get the latest entered word in textbox not the last word. And I want to change that latest entered word on space key pressed. I am getting the last word on a key up 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 am getting the last word by this method but actually I want to get latest entered word by user. Meaning, if the user moves the cursor directly to the middle of textbox and types any word then I want to get that word on space key pressed event; I want the position of that word and can change that word programmatically and update textbox. For example, if the user types
H!! my name vanani
but then the user moves the cursor directly after 'name' and types 'is sohan'
H!! my name is sohan
then I want to get word and position of 'is' and same for 'sohan' in key up event of textbox. I need the position to replace that word with another word and update textbox with the new replaced text.
I have seen these questions. winforms - get last word.. and C# how to get latest char.. but they didn't help me. Please help me.