replace spaces with   from a recordset

2019-05-17 13:26发布

问题:

hi guys how will i be able to change "spaces" on records being returned by a recordset.

for example I have this code that will return a value of "John Doe":

<td width="30%"><%=rsTmp("Name")%></font></td>

What I would like to do is to change the space between the words into:

&nbsp;

so that when my page got congested the name "John Doe" will still be in a straight line and will not be separated.

Thanks in advance!

回答1:

In Classic ASP you will need to code the following:

<%= Replace(rsTmp("Name")," ","&nbsp;") %>

Which is the same as

<%
    Response.Write ( Replace(rsTmp("Name")," ","&nbsp;") )
%>


回答2:

Actually, I would suggest using replace(rsTmp("Name"), " ", "&#160;")

In HTML5 the ASCII code &nbsp; are replaced with &#160;. You might as well do this from this day and onwards ;)



回答3:

I resolved it! I used replace function like this.

<% Replace(rsTmp("Name")," ","&nbsp;")%>