Skip to content

format html in a for() with int and string

Featured Replies

hi, any can help me with this?

 

have this code

 

int[] arr = new int[] {0254,0156,0641,0974,0112};

html.append("<table border=1 valign=\"center\" width=270 height=30 background=\"L2UI_CT1.Windows_DF_Drawer_Bg\">");
html.append("<tr>");
for(int i:arr){

	html.append("<td width=30><img src=\"icon.customtex_" + i + "\" width=32 height=32></td>");
	html.append("<td align=\"center\" width=290>Name 1!</td>");
}
html.append("</tr>");
html.append("</table>");

 

i need loop for 5 differents names.. but i no have idea how to make this..

 

thanks

  • Author

if any have this idea, i solved with this..

 

int[] arr = new int[] {0254,0156,0641,0974,0112};
String[] arr2 = new String[] {"A","B","C","D","E"};
for(int i=0; i<arr.length; i++){ 
    html.append("<td width=30><img src=\"icon.customtex_" + arr[i] + "\" width=32 height=32></td>"); 
    html.append("<td align=\"center\" width=290>" + arr2[i] + "</td>");
}

 

locked.

2 hours ago, StarSCreams said:

if any have this idea, i solved with this..

 


int[] arr = new int[] {0254,0156,0641,0974,0112};
String[] arr2 = new String[] {"A","B","C","D","E"};
for(int i=0; i<arr.length; i++){ 
    html.append("<td width=30><img src=\"icon.customtex_" + arr[i] + "\" width=32 height=32></td>"); 
    html.append("<td align=\"center\" width=290>" + arr2[i] + "</td>");
}

 

locked.

Your code cant run that way, an int that starts with 09 is just not allowed in this specific example.

If you need '0' at the begging of of any int, you should format it.

ex:

Arrays.asList(254,156,641,974,112).forEach(val -> html.append(String.format("<td width=30><img src=\"icon.customtex_%s\" width=32 height=32></td>",String.format("0%s", val))));
Arrays.asList("A","B","C","D","E").forEach(val -> html.append(String.format("<td align=\"center\" width=290>%s</td>",val)));

 

  • Author
29 minutes ago, melron said:

Your code cant run that way, an int that starts with 09 is just not allowed in this specific example.

If you need '0' at the begging of of any int, you should format it.

ex:


Arrays.asList(254,156,641,974,112).forEach(val -> html.append(String.format("<td width=30><img src=\"icon.customtex_%s\" width=32 height=32></td>",String.format("0%s", val))));
Arrays.asList("A","B","C","D","E").forEach(val -> html.append(String.format("<td align=\"center\" width=290>%s</td>",val)));

 

 

 

hey bro the int numbers are only example, but i learn if need 0 at the begging thank you =)

Or simply store a String and not an int, which avoid format operations.

 

To avoid to get inconsistencies between the 2 String array, you can also store it under a pair of String/String, or a Map<String, String> / String[][] - at least the result is reliable and data stays consistant.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.