For example: I want to convert string[] str = {"4", "5", "6"} to "' 4 ', ' 5 ', ' 6 '" string. So I can use SQL query: SELECT * FROM tablename ID in (string).
The source code implemented in the project is as follows:
Copy Code code as follows:
StringBuffer idsstr = new StringBuffer ();
for (int i = 0; i < ids.length; i++) {
if (i > 0) {
Idsstr.append (",");
}
Idsstr.append ("'"). Append (Ids[i]). Append ("'");
}
Another way I thought of it was as follows:
Copy Code code as follows:
public static String Stringarray2strin (string[] str) {
Stringbuffe R sb = new StringBuffer ();
for (int i = 0; i < str.length i++) {
Sb.append ("'). Append (Str[i]). Append (" "). Append (", ");
}
Return sb.tostring (). substring (0, Sb.length ()-1);
}
public static void Main (string[] args) {
string[] str = {"4", "5", "6"};
System.out.println (itemgroupservice.stringarray2string (str));
}