You may want to use Regex , a sample code below may help
string inputString = "key.addListener .addListener";
string patternToReplace= @"\B.addListener\b";
string result = Regex.Replace(inputString , patternToReplace, "");
Now result will contain string for which only whole word .addListener is removed
Note: Since the start of hte word you are looking to remove is . the first part of the regex is /B
If it is normal word like addListener without the . then use /b
at the start of the regex pattern.
Hope that helps.
Do mark as answer/upvote if it helps