Skip to content

Instantly share code, notes, and snippets.

@d3ep4k
Created January 14, 2015 07:38
Show Gist options
  • Save d3ep4k/1556d676b0dc48379d6a to your computer and use it in GitHub Desktop.
Save d3ep4k/1556d676b0dc48379d6a to your computer and use it in GitHub Desktop.
Function to Construct String from array of data
String construct(String start, String middle, String end, String data){
StringBuilder construct = new StringBuilder();
String[] tokens = data.split(",");
int i=0;
construct.append(start);
while(i<tokens.length -1){
construct.append(middle.replaceAll("%s", tokens[i]));
i++;
}
construct.append(end.replaceAll("%s", tokens[i]));
return construct.toString();
}
String data = "a,b,c,d,e,f,g,h";
//Call
construct("AND( ", "LIKE '%s' OR ", "LIKE '%s')",data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment