可以说我有两个字符串:
string s1 = "hello";
string s2 = "hello world";
Run Code Online (Sandbox Code Playgroud)
有没有办法可以得到一个string s3 = " world";
两个字符串之间的区别?
编辑:
在这种情况下,差异将始终存在
s1 = "abc"
s2 = "abcd ads as "
Run Code Online (Sandbox Code Playgroud)
Pau*_*ora 26
使用 string s3 = s2.Replace(s1, "");
编辑:请注意,所有出现s1
在s2
将不会出席s3
.请务必仔细考虑此帖子上的评论,以确认这是您想要的结果,例如@mellamokb评论中提到的情景.
string s1 = "hello";
string s2 = "hello world";
string s3 = s2.replace(s1,"");
Run Code Online (Sandbox Code Playgroud)
如果您定义的案例是正确的,则替代解决方案将是:
string s3 = s2.substring(s1.Length);
Run Code Online (Sandbox Code Playgroud)
这假设第二个字符串以与第一个字符串完全相同的字符开头,您只想切断初始复制.