Created
January 14, 2015 07:38
-
-
Save d3ep4k/1556d676b0dc48379d6a to your computer and use it in GitHub Desktop.
Function to Construct String from array of data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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