How can i remove the comma?

Reply

Join Date: Aug 2005
Posts: 52
Reputation: spidey is an unknown quantity at this point 
Solved Threads: 0
spidey's Avatar
spidey spidey is offline Offline
Junior Poster in Training

How can i remove the comma?

 
0
  #1
Mar 3rd, 2006
hi peeps,

i have here a code of the contents in a field fetched from the database. the ProductID is looped until all are displayed, which depends on the sql. i put a comma after a ProductID so that all ProductIDs are displayed separated by a comma and a single space. my problem is that after the last ProductID, there is still a comma displayed. how can i remove the comma after the last ProductID??

hope you got what i mean and can help me with this problem.

thank you once again and more power to you & daniweb!!

  1. <%do until rsprd.eof%>
  2. <%'sTotal = 1%>
  3. <%lght = Len(rsprd("ProductID"))%>
  4. <%if lght = 1 then%>
  5. <%if rsprd.recordcount = 1 then%>
  6. <font size="2" face="Arial" color="#000000">P-000<%=rsprd("ProductID")%>,</font>
  7. <%else%>
  8. <font size="2" face="Arial" color="#000000">P-000<%=rsprd("ProductID")%>,</font>
  9. <%end if%>
  10. <% elseif lght =2 then%>
  11. <%if rsprd.recordcount = 1 then%>
  12. <font size="2" face="Arial" color="#000000">P-00<%=rsprd("ProductID")%>,</font>
  13. <%else%>
  14. <font size="2" face="Arial" color="#000000">P-00<%=rsprd("ProductID")%>,</font>
  15. <%end if%>
  16. <%elseif lght = 3 then%>
  17. <%if rsprd.recordcount = 1 then%>
  18. <font size="2" face="Arial" color="#000000">P-0<%=rsprd("ProductID")%>,</font>
  19. <%else%>
  20. <font size="2" face="Arial" color="#000000">P-0<%=rsprd("ProductID")%>,</font>
  21. <%end if%>
  22. <%elseif lght = 4 then%>
  23. <%if rsprd.recordcount = 1 then%>
  24. <font size="2" face="Arial" color="#000000">P-<%=rsprd("ProductID")%>,</font>
  25. <%else%>
  26. <font size="2" face="Arial" color="#000000">P-<%=rsprd("ProductID")%>,</font>
  27. <%end if%>
  28. <%end if%>
  29.  
  30. <%rsprd.Movenext
  31. loop
  32. sTotal = sTotal + (rsprd.recordcount)%>
  33.  
  34. <%'else%>
  35. &nbsp;
  36. <%'end if%>
  37. </font>
  38. <%end if%>
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 166
Reputation: Lafinboy is an unknown quantity at this point 
Solved Threads: 7
Lafinboy's Avatar
Lafinboy Lafinboy is offline Offline
Junior Poster

Re: How can i remove the comma?

 
0
  #2
Mar 13th, 2006
You would be better off building the output into a variable rather than writing it directlt to the sreen as part of the loop. You can then use the LEFT and STRLEN functions to trim the required number of characters from the end of the resultant variable. An example:
  1. tempStr = ""
  2. x=1
  3. do while x<=10
  4. tempStr = tempStr & x & ","
  5. loop
  6. '// output would be
  7. '// 1,2,3,4,5,6,7,8,9,10,
  8. tempStr = left(tempStr, strlen(tempStr)-1)
  9. '// output would be
  10. '// 1,2,3,4,5,6,7,8,9,10
If I've been a help please confirm by clicking the Add to Lafinboy's Reputation link in the header of this reply.

Lafinboy Productions
:: Website Design :: Website Development ::

Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the ASP Forum


Views: 2638 | Replies: 1
Thread Tools Search this Thread



Tag cloud for ASP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC