两个字符串C#的区别 [英] Difference between two strings C#

查看:109
本文介绍了两个字符串C#的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以说我有两个字符串:

 字符串S1 =你好; 
字符串s2 =Hello World的;



有没有一种方法可以让我得到一个串S3 =世界; ?这是2串之间的差异



编辑:



的差异在这种情况下

  S1 =ABC
S2 =ABCD始终广告为


解决方案

使用字符串S3 = s2.Replace(S1,);



编辑:请注意,所有出现的 S1 S2 将是 S3 。请务必慎重地考虑这个帖子上的评论,以确认这是你想要的结果,例如在 @mellamokb 提到的场景的评论。


Lets say I have two strings:

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

Is there a way I can get a string s3 = " world"; which is the difference between the 2 strings?

EDIT:

The difference will be always in this scenario

s1 = "abc"
s2 = "abcd ads as "

解决方案

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.

这篇关于两个字符串C#的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆