Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Eliminating commas within a concatenated string

Status
Not open for further replies.

marydn

Programmer
Mar 26, 2001
152
US
Hi,

I concatenate an address in SQL and when I call the data in the ASP page I see all the commas where there is no address. I want to eliminate the commas.

For example:

123 Elm Street, Miami, FL 20333

If there is no adress it shows as:
, ,
on the page.

I am sure this an easy fix, but not for me....

THANKS!
 
Try this:
Code:
<%
Function TrimAddr(mystr)
  svaddr=&quot; &quot;+mystr
  do while instr(svaddr,&quot; ,&quot;)>0
    svaddr=Replace(svaddr, &quot; ,&quot;,&quot;&quot;)
  loop
  TrimAddr=svaddr
End Function

MyAddr=&quot;123 Elm Street, Miami, FL 20333&quot;
response.write(&quot;'&quot;+TrimAddr(MyAddr)+&quot;'<br>&quot;)

MyAddr=&quot;, , &quot;
response.write(&quot;'&quot;+TrimAddr(MyAddr)+&quot;'<br>&quot;)
%>
 
So you have a string that may consist of &quot;,,&quot;, or &quot;, ,&quot;.

You could handle this in the ASP script like so.
Code:
Dim strAddress
strAddress = rsGet.Fields(&quot;address&quot;).Value
If strAddress = &quot;,,&quot; Then
   strAddress = &quot; &quot;
EndIf

Or you could handle it in SQL like so.
Code:
SELECT 
   CASE
      WHEN addr_line_1 = &quot;&quot; THEN &quot;&quot;
      WHEN addr_line_2 = &quot;&quot; THEN addr_line_1 + &quot;, &quot; + city + &quot;, &quot; + state + &quot;  &quot; + zip
      ELSE addr_line_1 + addr_line_2 + &quot;, &quot; + city + &quot;, &quot; + state + &quot;  &quot; + zip
   END AS &quot;address&quot;

Actually that might not be the best logic but you get the idea.
 
just for kicks even knowing I doubt I'd create the object for a comma (however you can pass the comma and anything else to the a function as this and then it would be worth it)

Set regObj = New RegExp
regObj.pattern = &quot;,&quot;
regObj.global = true
str = &quot;string, that, may, consist, of ,,, or ,,,,, ,.&quot;
str = regObj.replace(str,&quot; &quot;)

_____________________________________________________________________
onpnt2.gif

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top