n00b0101
n00b0101

Reputation: 6893

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) { %>
<%= o_handler.renderDDesc()%>
<%}%> 

But, that didn't seem to do anything. I didn't get an error, but it also didn't appear?

Upvotes: 0

Views: 116

Answers (3)

Jason
Jason

Reputation: 89204

<%

string desc = o_handler.renderDesc();

if (!String.IsNullOrEmpty(desc)) { 
Response.Write(desc);
}

%> 

Upvotes: 1

Keith Adler
Keith Adler

Reputation: 21178

I would simply use a ternary operator as follows:

<%=( o_Handler.IsNullOrEmpty() ? string.Empty : o_handler.renderDDesc() ); %>

Upvotes: 0

D&#39;Arcy Rittich
D&#39;Arcy Rittich

Reputation: 171579

<%= !String.IsNullOrEmpty(o_handler.renderDDesc()) ? o_handler.renderDDesc() : ""%>

Upvotes: 0

Related Questions