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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×
×
  • Create New...

Important Information

This community uses essential cookies to function properly. Non-essential cookies and third-party services are used only with your consent. Read our Privacy Policy and We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue..

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock