ASP Question - How to count # of characters?
Today is the very first day I've ever even seen aspx, so, please bear with me...
Basically, I want to determine if a string is empty. If it is empty, then I don't want anything to output, if it's not, then I want to output the string itself.
<%= o_handler.renderDDesc()%> //This is the string itself... If this is empty, then I want I want nothing to print
I tried:
<%if (o_handler.renderDDesc().length() > 0) 开发者_StackOverflow{ %>
<%= o_handler.renderDDesc()%>
<%}%>
But, that didn't seem to do anything. I didn't get an error, but it also didn't appear?
<%
string desc = o_handler.renderDesc();
if (!String.IsNullOrEmpty(desc)) {
Response.Write(desc);
}
%>
<%= !String.IsNullOrEmpty(o_handler.renderDDesc()) ? o_handler.renderDDesc() : ""%>
I would simply use a ternary operator as follows:
<%=( o_Handler.IsNullOrEmpty() ? string.Empty : o_handler.renderDDesc() ); %>
精彩评论