Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

循环中拼接字符串 #182

Open
QiAnXinCodeSafe opened this issue Dec 29, 2020 · 3 comments
Open

循环中拼接字符串 #182

QiAnXinCodeSafe opened this issue Dec 29, 2020 · 3 comments

Comments

@QiAnXinCodeSafe
Copy link

String s = "";
if (array != null) {
if (split == null) {
split = ",";
}
for (int i = 0; i < array.length; i++) {
if (ignoreEmptyItem && isEmpty(array[i], true)) {
continue;
}
s += ((i > 0 ? split : "") + array[i]);
}
}

String numberString = "";
String single;
for (int i = 0; i < s.length(); i++) {
single = s.substring(i, i + 1);
if (isNumer(single)) {
numberString += single;
} else {
if (onlyStart) {
return numberString;
}
}
}

String correctPrice = "";
String s;
for (int i = 0; i < price.length(); i++) {
s = price.substring(i, i + 1);
if (".".equals(s) || isNumer(s)) {
correctPrice += s;
}
}

建议在循环中使用StringBuilder拼接字符串

@TommyLemon
Copy link
Collaborator

感谢建议,当时为了快速开发就简单拼接了,现在确实要优化下

@kxlv2000
Copy link
Contributor

您好,
请问问题解决了吗,可以允许我尝试优化此问题吗?

@TommyLemon
Copy link
Collaborator

TommyLemon commented Mar 12, 2021

您好,
请问问题解决了吗,可以允许我尝试优化此问题吗?

还没有,当然可以,非常感谢,具体步骤可参考本页 #Pull Request 说明
https://github.com/Tencent/APIJSON/blob/master/CONTRIBUTING.md#%E4%B8%BA%E4%BB%80%E4%B9%88%E4%B8%80%E5%AE%9A%E8%A6%81%E8%B4%A1%E7%8C%AE%E4%BB%A3%E7%A0%81

Rkyzzy added a commit to Rkyzzy/APIJSON that referenced this issue Apr 22, 2021
将StringUtil.java类中三处字符串直接拼接优化为使用StringBuilder拼接
issue Tencent#182
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants