Jump to content
  • 0

format html in a for() with int and string


Question

Posted

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

5 answers to this question

Recommended Posts

  • 0
Posted

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.

  • 0
Posted
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)));

 

  • 0
Posted
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 =)

  • 0
Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...