Use string.Replace to match whole words

后端 未结 3 813
逝去的感伤
逝去的感伤 2021-01-21 16:50

I\'m using NET 2.0 and WinForms.

Currently, I need a code to replace a string with another one in a given text, but in the text it should only look for whole words. What

3条回答
  •  别那么骄傲
    2021-01-21 17:18

    Small workaround:

    string name = @"COUNTER = $40
    CLOCK_COUNTER = $60";
    name=" "+name;
    name = name.Replace(" COUNTER ", " COUNT ");
    

    Main idea that you have to mark the word you're going to replace with some sort of symbols that other words that you do not want to replace have not

提交回复
热议问题