Reputation: 137
I have a string:
Am trying to do the below :
int i =0;
for(String s : appFields){
i++;
String divid = "chart_"+i;
divid = divid.replaceAll("[\\r\\n]+$", "");
}
I would like to trim it so that the value is only chart_1
and so on.
Can someone help me please?
<%
String[] appFields = "Account Information,Action Status,Activity Name,Activity Status,Last Activity Timestamp,Geographical Region,Enterprise Status,Business Process,Numer of Pages,Message Direction".split(",");
int i =0;
for(String s : appFields){
i++;
String divid = "chart_"+i;
divid = divid.replaceAll("[\\r\\n]+$", "");
%>
<tr>
<td><% out.println(i); %></td>
<td><% out.println(s); %></td>
<td class='with-3d-shadow with-transitions'><p><svg id="<% out.println(divid); %>" class="sparkline"></svg></p></td>
</tr>
<%
}
%>
This is the output i get in Chrome Web Inspector
<td class="with-3d-shadow with-transitions"><p><svg id="chart_1
" class="sparkline"></svg></p></td>
Upvotes: 1
Views: 196
Reputation: 6243
temp = temp.trim();
String
s are immutable so operations return new String
s that you have to assign back to the original reference variable.
Upvotes: 6
Reputation: 280170
Change your line to
<svg id="<%out.print(divid);%> " class="sparkline"></svg>
In other words, use print
instead of println
. println
adds a new line after your String
.
Upvotes: 1