使用字符串连接显示0而不是null [英] using string concatenation display 0 instead of null

查看:126
本文介绍了使用字符串连接显示0而不是null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含文本框的表格,搜索"按钮.当用户输入值并单击按钮时,我必须显示搜索详细信息.我必须显示搜索结果数:我通过使用array.length获得的搜索结果数;我想在另一个视图页面中使用此值.所以我将此值放在sessionStorage.setItem("getCount",len);中.我在其他视图页面中添加了此值,例如:

I have a form which contains textboxes,"search" button.when user enter the values and click on the button I have to display the search details. and I have to display no.of searchresults: no.of search results i have obtained by using array.length; I want to use this value in another view page.so I put this value in the sessionStorage.setItem("getCount",len); I am concatinating this value in the other view page like:

Search Results:" + sessionStorage.getItem('getCount') + "



当用户在表单中输入值时,我得到的搜索结果数.但是,当用户未在表单中输入任何值时,则在searchresults:它显示为"null".但是我想显示为null的"0".



I am getting the number of search results when user enters the value in the form. but when user enter no values in the form then at the searchresults: it is displaying "null".but i want to display "0" insted of null. how can i do this.

推荐答案

如果您使用的是C#,则一个简单的if-else语句应该可以工作.像这样的东西:
If you''re using C# then a simple if-else statement should work. Something like:
..."Search Results:" + sessionStorage.getItem('getCount') == null ? 0 : (int)sessionStorage.getItem('getCount')


尽管您在这里没有提及编码所用的语言,但可能这样...
Though you not mentioned here what language you used for coding but it may be something like that...
if(sessionStorage.getItem('getCount').toString() == '0')
  then print 0;  //or your preferred message
else
  Search Results:" + sessionStorage.getItem('getCount') + "  //your preferred work


这篇关于使用字符串连接显示0而不是null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆