问题描述
我试图找到一种方法,如何比较两个字符串并升级第一个,当第二个更多的时候。
例如
I am trying to find a way, how to compare two strings and upgrade the first, when the second has more in it.For example
String A="This is a statement!";
String B="This is a statement! Good luck!";
if(A<B{ //B has more letters
//Upgrade A }
else{ //Upgrade B
}
我的意思是升级不会覆盖像A = B
我的字符串通常有很多行
我想保留字符串的值,只是从另一个String插入新的东西
有人有个想法吗?
I mean with upgrade not overwriting like A=B.My strings has usually much lines.I want to keep the value of the string and just insert the new things from the other String.Has someone an idea?
编辑:谢谢
不幸的是,我没有提供更清楚,对不起我的错。
我的问题是,我现在知道更改的位置,字符串可能如下所示:
Thank you for the nice answers.Unfortunetly I didnt exlain it more clear, sorry my fault.My problem is, that I do now know where the changes are, the strings could look like this:
String A:
A
B
C//Good morning, sir
D//A comment
E
String B:
A
B//Yes
C
D
DD
E
The result should be:
A
B//Yes
C//Good morning, sir
D//A comment
DD
E
推荐答案
p>我想你需要这样的东西:
I guess you need something like this:
String A="This is a statement!";
String B="This is a statement! Good luck!";
if (A.length() < B.length()){ //B has more letters
A += B.subString(A.length(), B.length()-1);
} else{
B += A.subString(B.length(), A.length()-1);
}
希望这是你要找的:)。
Hope this is what you are looking for :).
这篇关于比较和更新一个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!