[英]Replace first and last character upon condition (which method is faster)?
I have a list of thousands of strings that may come in the form: 我列出了成千上万的字符串,它们的形式可能是:
word
字
or 要么
"more than one word"
“一个字以上”
I want to remove the "" whenever they are present, so that I can save the string to my DB. 我想删除出现的“”,以便将字符串保存到数据库中。
I'm wondering which method is faster: 我想知道哪种方法更快:
line.replace("\\"","");
line.replace("\\"","");
Or even, is there a better way to do this? 甚至,还有更好的方法吗?
The second method is faster. 第二种方法更快。 It will perform at most one character comparison and one array copy, instead of comparing all characters in the string with the " character.
它将最多执行一个字符比较和一个数组副本,而不是将字符串中的所有字符与“字符”进行比较。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.