Difference between two strings C#

前端 未结 6 1055
小蘑菇
小蘑菇 2020-12-17 10:23

Lets say I have two strings:

string s1 = \"hello\";
string s2 = \"hello world\";

Is there a way I can get a string s3 = \" world\";

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-17 10:29

    Use string s3 = s2.Replace(s1, "");

    EDIT: Note that all occurrences of s1 in s2 will be absent from s3. Make sure to carefully consider the comments on this post to confirm this is your desired result, for example the scenarios mentioned in @mellamokb's comment.

提交回复
热议问题